Javascript asp.net;。d";在客户端解析JSON失败

Javascript asp.net;。d";在客户端解析JSON失败,javascript,c#,asp.net,json,Javascript,C#,Asp.net,Json,我的asmx页面的配置如下 using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.Script.Serialization; using System.Web.Services; using Time.CSharpclasses; /// <summary> /// Summary descript

我的asmx页面的配置如下

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Services;
using Time.CSharpclasses;
/// <summary>
/// Summary description for LiquidityMonthAjax
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class LiquidityMonthAjax : System.Web.Services.WebService
前者是通过serializeJSONObject方法给我带来问题的方法 如下:

public static String serializeJSONObject(Object items)
    {
        System.Web.Script.Serialization.JavaScriptSerializer serializer = new

       System.Web.Script.Serialization.JavaScriptSerializer();
        serializer.MaxJsonLength = 2147483644;




        return serializer.Serialize(items);
    }

我真的不认为那种方法是问题所在,因为我以前已经成功地使用过一百次了。

有些版本的.Net平台返回
d
有些没有。尝试在代码中添加类似的内容:

var data = (response.hasOwnProperty("d")) ? d : response;
现在,
数据
包含响应,无论使用哪个版本的.Net,都会使客户端代码更加健壮


戴夫·沃德(Dave Ward)为此写了一篇博客:

显然问题出在客户端。我忘了字符串化我的对象,所以jquery礼貌地将aguments包装在url查询中。ASP.net的一个函数表示,如果请求不是JSON,则响应是XML,从而放弃请求头类型和程序员将其设置为JSON的任何尝试。 请参阅JSON、对象和字符串下的链接:哦,天哪


你应该展示整个webservice方法以及你在response.d中的内容,这样有人可以帮助你。response.d是未定义的。你需要定义类并返回它。@mybirthname你的意思是要返回一个新对象,而不是自己打包json,让[System.Web.Script.Services.ScriptService]帮我做?或者别的什么?是的,最好的方法是创建新的对象作为类,我会给你举个例子。您还需要向该方法添加另一个属性。
public static String serializeJSONObject(Object items)
    {
        System.Web.Script.Serialization.JavaScriptSerializer serializer = new

       System.Web.Script.Serialization.JavaScriptSerializer();
        serializer.MaxJsonLength = 2147483644;




        return serializer.Serialize(items);
    }
var data = (response.hasOwnProperty("d")) ? d : response;