不幸的是,客户端只支持VS 2008(框架3.5),不知道为什么我的json被包装在xml中。使用webforms。
我的JSON回复了:
<?xmlversion="1.0"encoding="utf-8"?><stringxmlns="http://tempuri.org/">[
{
"Name": "AAA",
"Company": "AAAA",
"Address": "AAAA",
"Phone": "1204675",
"Country": "US"
},
{
"Name": "AAAA",
"Company": "AAAA",
"Address": "AAAA",
"Phone": "AAA",
"Country": "AAA"
}
]</string>
我的ASCX代码:
[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 HCTCService : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string TestJSON()
{
Employee[] e = new Employee[2];
e[0] = new Employee();
e[0].Name = "AAA";
e[0].Company = "AAAA";
e[0].Address = "AAAA";
e[0].Phone = "1204675";
e[0].Country = "US";
e[1] = new Employee();
e[1].Name = "AAAA";
e[1].Company = "AAAA";
e[1].Address = "AAAA";
e[1].Phone = "AAA";
e[1].Country = "AAA";
return new JavaScriptSerializer().Serialize(e);
}
}
}