asp.net 2.0 asmx WebService在JSON响应中排除类型

asp.net 2.0 asmx WebService在JSON响应中排除类型,asp.net,json,web-services,asp.net-ajax,Asp.net,Json,Web Services,Asp.net Ajax,我试图确定如何从asmx Web服务中排除JSON响应中的\uuu type 我返回的类构造如下 public class MyClassName { private string _item1 = string.Empty; private string _item2 = string.Empty; public string item1 = { get { return _item1; } set { _item1 = value; } } public s

我试图确定如何从asmx Web服务中排除JSON响应中的
\uuu type

我返回的类构造如下

public class MyClassName
{
    private string _item1 = string.Empty;
    private string _item2 = string.Empty;

    public string item1 = { get { return _item1; } set { _item1 = value; } }
    public string item2 = { get { return _item2; } set { _item2 = value; } }
}

public class MyClassName_List : List<MyClassName>
{
    public MyClassName_List() {}
}
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class MyClassName_WebService : System.Web.Services.WebService
{
    [WebMethod]
    public MyClassName_List GetList()
    {
        return MyClassName_List_BusinessLogicLayer.GetList();
    }
}
[
    {
    item1: "item1-1 text",
    item2: "item1-2 text",
    __type: "NamespaceUsed.MyClassName"
    },
    {
    item1: "item2-1 text",
    item2: "item2-2 text",
    __type: "NamespaceUsed.MyClassName"
    },
]
[
    {
    item1: "item1-1 text",
    item2: "item1-2 text"
    },
    {
    item1: "item2-1 text",
    item2: "item2-2 text"
    }
]
public class MyClassName
{
    private string _item1 = string.Empty;
    private string _item2 = string.Empty;

    public string item1 = { get { return _item1; } set { _item1 = value; } }
    public string item2 = { get { return _item2; } set { _item2 = value; } }

    protected internal MyClassName() { } //add a protected internal constructor to remove the returned __type attribute in the JSON response
}

public class MyClassName_List : List<MyClassName>
{
    public MyClassName_List() {}
}
JSON对象返回的结构如下所示

public class MyClassName
{
    private string _item1 = string.Empty;
    private string _item2 = string.Empty;

    public string item1 = { get { return _item1; } set { _item1 = value; } }
    public string item2 = { get { return _item2; } set { _item2 = value; } }
}

public class MyClassName_List : List<MyClassName>
{
    public MyClassName_List() {}
}
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class MyClassName_WebService : System.Web.Services.WebService
{
    [WebMethod]
    public MyClassName_List GetList()
    {
        return MyClassName_List_BusinessLogicLayer.GetList();
    }
}
[
    {
    item1: "item1-1 text",
    item2: "item1-2 text",
    __type: "NamespaceUsed.MyClassName"
    },
    {
    item1: "item2-1 text",
    item2: "item2-2 text",
    __type: "NamespaceUsed.MyClassName"
    },
]
[
    {
    item1: "item1-1 text",
    item2: "item1-2 text"
    },
    {
    item1: "item2-1 text",
    item2: "item2-2 text"
    }
]
public class MyClassName
{
    private string _item1 = string.Empty;
    private string _item2 = string.Empty;

    public string item1 = { get { return _item1; } set { _item1 = value; } }
    public string item2 = { get { return _item2; } set { _item2 = value; } }

    protected internal MyClassName() { } //add a protected internal constructor to remove the returned __type attribute in the JSON response
}

public class MyClassName_List : List<MyClassName>
{
    public MyClassName_List() {}
}
我只想返回JSON对象,如下所示

public class MyClassName
{
    private string _item1 = string.Empty;
    private string _item2 = string.Empty;

    public string item1 = { get { return _item1; } set { _item1 = value; } }
    public string item2 = { get { return _item2; } set { _item2 = value; } }
}

public class MyClassName_List : List<MyClassName>
{
    public MyClassName_List() {}
}
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class MyClassName_WebService : System.Web.Services.WebService
{
    [WebMethod]
    public MyClassName_List GetList()
    {
        return MyClassName_List_BusinessLogicLayer.GetList();
    }
}
[
    {
    item1: "item1-1 text",
    item2: "item1-2 text",
    __type: "NamespaceUsed.MyClassName"
    },
    {
    item1: "item2-1 text",
    item2: "item2-2 text",
    __type: "NamespaceUsed.MyClassName"
    },
]
[
    {
    item1: "item1-1 text",
    item2: "item1-2 text"
    },
    {
    item1: "item2-1 text",
    item2: "item2-2 text"
    }
]
public class MyClassName
{
    private string _item1 = string.Empty;
    private string _item2 = string.Empty;

    public string item1 = { get { return _item1; } set { _item1 = value; } }
    public string item2 = { get { return _item2; } set { _item2 = value; } }

    protected internal MyClassName() { } //add a protected internal constructor to remove the returned __type attribute in the JSON response
}

public class MyClassName_List : List<MyClassName>
{
    public MyClassName_List() {}
}

我尝试了来自的建议,但似乎无法正确实施。非常感谢您在这方面的任何帮助

方法如下

public class MyClassName
{
    private string _item1 = string.Empty;
    private string _item2 = string.Empty;

    public string item1 = { get { return _item1; } set { _item1 = value; } }
    public string item2 = { get { return _item2; } set { _item2 = value; } }
}

public class MyClassName_List : List<MyClassName>
{
    public MyClassName_List() {}
}
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class MyClassName_WebService : System.Web.Services.WebService
{
    [WebMethod]
    public MyClassName_List GetList()
    {
        return MyClassName_List_BusinessLogicLayer.GetList();
    }
}
[
    {
    item1: "item1-1 text",
    item2: "item1-2 text",
    __type: "NamespaceUsed.MyClassName"
    },
    {
    item1: "item2-1 text",
    item2: "item2-2 text",
    __type: "NamespaceUsed.MyClassName"
    },
]
[
    {
    item1: "item1-1 text",
    item2: "item1-2 text"
    },
    {
    item1: "item2-1 text",
    item2: "item2-2 text"
    }
]
public class MyClassName
{
    private string _item1 = string.Empty;
    private string _item2 = string.Empty;

    public string item1 = { get { return _item1; } set { _item1 = value; } }
    public string item2 = { get { return _item2; } set { _item2 = value; } }

    protected internal MyClassName() { } //add a protected internal constructor to remove the returned __type attribute in the JSON response
}

public class MyClassName_List : List<MyClassName>
{
    public MyClassName_List() {}
}
公共类MyClassName
{
私有字符串_item1=string.Empty;
私有字符串_item2=string.Empty;
公共字符串item1={get{return}u item1;}set{{u item1=value;}}
公共字符串item2={get{return}u item2;}set{{u item2=value;}}
受保护的内部MyClassName(){}//添加受保护的内部构造函数以删除JSON响应中返回的_类型属性
}
公共类MyClassName\u列表:列表
{
公共MyClassName_List(){}
}

我希望这对其他人也有帮助

我已经搜索了2个小时,这个答案很快就解决了!谢谢很高兴有帮助!如果你有任何问题,请告诉我。我已经用了很长一段时间,现在没有任何问题!