我在Web上发现了几个针对WCF Web服务而不是ASP Web服务的解决方案。如何从ASP Web服务的JSON响应中删除d:和__type
目前,我取回一个JSON响应,上面写着:
{"d":[{"__type":"NetworkFuzzWebSvc.Sessions","BaseUri":"http://localbox","SessionId":"43b8716f-40ab-43bf-8311-575c2ecd2730}]}
我需要它返回:
{"Sessions":["BaseUri":"http://localbox","SessionId":"43b8716f-40ab-43bf-8311-575c2ecd2730}]}
下面是Web服务代码的副本,我使用(NetFuzzWebSvc.asmx):
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
namespace NetworkFuzzWebSvc
{
public class Sessions
{
public string BaseUri;
public string SessionId;
}
/// <summary>
/// Summary description for NetFuzzJson
/// </summary>
[WebService(Namespace = "http://localbox")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class NetFuzzJson : WebService
{
List<Sessions> Sessions = new List<Sessions>
{
new Sessions{
BaseUri = "http://localbox/",
SessionId="43b8716f-40ab-43bf-8311-575c2ecd2730"
}
};
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<Sessions> GetAllSessions()
{
return Sessions;
}
}
任何人都有解决方案吗? 谢谢!
我必须设置'automaticFormatSelectionEnabled'假在我的配置,否则我结束了一个XML resposne,而不是一个JSON一个,否则该工作一种享受:您还可以通过
Type
与更改此行为。 –