Javascript 使用$.ajax和C的JSON格式
如果我使用$.ajax JQuery并调用WebMethod,我会得到JSON:Javascript 使用$.ajax和C的JSON格式,javascript,c#,jquery,json,ajax,Javascript,C#,Jquery,Json,Ajax,如果我使用$.ajax JQuery并调用WebMethod,我会得到JSON: $.ajax({ type: "POST", dataType: "json", data: JSON.stringify({ id: idX, id2: idY }), async: true, cache: false, url: "/ws/Courses.asmx/GetCourses", contentType: "application/json;
$.ajax({
type: "POST",
dataType: "json",
data: JSON.stringify({ id: idX, id2: idY }),
async: true,
cache: false,
url: "/ws/Courses.asmx/GetCourses",
contentType: "application/json; charset=utf-8",
success: function (data) {
RenderCourses(data.d);
},
});
但是JSON具有d属性
function RenderCourses(data) {
if (data.d.length > 0) {
string script = "var data = " + json + "; RenderCourses(data);";
ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "dataVar", script, true);
如果我在C中使用json=JsonConvert.Serialized对象,那么它没有d属性
function RenderCourses(data) {
if (data.d.length > 0) {
string script = "var data = " + json + "; RenderCourses(data);";
ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "dataVar", script, true);
而RenderCourses失败了
有什么原因吗?ADO.NET WebMethods总是这样序列化响应。d是指数据。你对此无能为力 JsonConvert.SerializeObject是来自第三方软件的方法。它只是简单地将对象序列化为JSON 在$.ajaxJSON.stringify中尝试数据:{id:idX,id2:idY},问题出在哪里?