【发布时间】:2014-03-20 09:34:24
【问题描述】:
我使用以下代码向我的 mvc 控制器发送/接收对象:
$.ajax({
url: _createOrUpdateTimeRecord,
data: JSON.stringify(data),
type: "POST",
//dataType: "json",
contentType: "application/json; charset=utf-8",
beforeSend: function () {
$("#loading-overlay").show();
},
success: function (data2) {
try { // tried to parse it manually to see if anything changes.
data2 = JSON.parse(data2);
}
catch (err) {
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError + 'xhr error -- ' + xhr.status);
}
});
在我的 mvc 控制器上,我将 JSON 对象作为字符串,所以我不需要 .NET JavascriptSerializer 和 JsonResult。
我的 JSON 字符串如下所示:
data2 = "{title:'1111111',start:'2014-03-23T16:00:00.000',end:'2014-03-23T18:00:00.000',id:107,hdtid:1,color:'#c732bd',allDay:false,description:''}"
我总是得到: “无效字符”
我已经尝试在客户端手动返回一个字符串并解析 JSON。因此我使用 ContentResult 作为返回类型但没有成功
public class JsonStringResult : ContentResult
{
public JsonStringResult(string json)
{
Content = json;
ContentType = "application/json";
}
}
这里有什么问题? JSON 看起来不错...
干杯, 斯蒂芬
【问题讨论】:
标签: jquery asp.net-mvc json asp.net-mvc-4