3
ASP.NET JSON序列化的DateTime以下格式 「/日期(1251877601000)/」。請幫助將此字符串解析爲java(GWT)Date對象。如何解析ASP.NET JSON日期格式與GWT
在這個時候,我想出了用正則表達式解析解,解長..但我無法通過JSNI長推。
ASP.NET JSON序列化的DateTime以下格式 「/日期(1251877601000)/」。請幫助將此字符串解析爲java(GWT)Date對象。如何解析ASP.NET JSON日期格式與GWT
在這個時候,我想出了用正則表達式解析解,解長..但我無法通過JSNI長推。
function FixJsonDates(data) {
//microsoft script service perform the following to fix the dates.
//json date:\/Date(1317307437667-0400)\/"
//javasccript format required: new Date(1317307437667-0400)
//copied from micrsoft generated fiel.
var _dateRegEx = new RegExp('(^|[^\\\\])\\"\\\\/Date\\((-?[0-9]+)(?:[a-zA-Z]|(?:\\+|-)[0-9]{4})?\\)\\\\/\\"', 'g');
var exp = data.replace(_dateRegEx, "$1new Date($2)");
return eval(exp);
}
回答這個問題時,使用的NuGet獲得JSON.NET然後用這個你JsonResult
方法內:
return Json(JsonConvert.SerializeObject(/* JSON OBJECT TO SEND TO VIEW */));
內您的視圖簡單的做到這一點在javascript
:
JSON.parse(@Html.Raw(Model.data))
如果通過是或視圖模型來,如果它是一個Ajax調用:
var request = $.ajax({ url: "@Url.Action("SomeAjaxAction", "SomeController")", dataType: "json"});
request.done(function (data, result) { JSON.parse(data); });
此代碼看起來不像GWT代碼。 – 2011-12-02 14:39:38