asp.net – 如何从ASP Web服务的JSON响应中删除d:和__type
发布时间:2020-12-16 00:15:12 所属栏目:asp.Net 来源:网络整理
导读:我在网上找到了几个针对WCF Web服务而不是ASP Web服务的解决方案. 目前,我正在收到一条JSON响应说: {"d":[{"__type":"NetworkFuzzWebSvc.Sessions","BaseUri":"http://localbox","SessionId":"43b8716f-40ab-43bf-8311-575c2ecd2730}]} 我需要它返回: {"Se
我在网上找到了几个针对WCF Web服务而不是ASP Web服务的解决方案.
目前,我正在收到一条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; } } 有人有解决方案吗? 解决方法
删除“d”和“__type”:
.SVC [ServiceContract] public interface ITestService { [OperationContract] [WebInvoke(Method = "POST",RequestFormat = WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json,BodyStyle = WebMessageBodyStyle.WrappedRequest)] List<TestDTO> GetAll(); } 的.config <behaviors> <endpointBehaviors> <behavior name="DebugJSonBehavior" > <enableWebScript /> <!--need set automaticFormatSelectionEnabled attribute --> <webHttp automaticFormatSelectionEnabled="true" /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="DebugJSonBehavior" > <serviceMetadata httpGetEnabled="true" /> <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> JS: $.ajax({ type: "POST",url: _serviceUrl + "/TestService.svc/GetAll",data: "{}",contentType: "application/json; charset=utf-8",dataType: "json",success: function (dataret) { ... },error: function (xmlHttpRequest,textStatus,errorThrown) {... },complete: function () { ... } }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – ASP.NET Azure 400错误请求不返回JSON数据
- ASP.NET’Session.Remove(key)’v / s’Session(key)= noth
- 上周热点回顾(3.4-3.10)
- 如何说服我的管理员从ASP.NET 2.0升级到3.5?
- 如何在ASP.NET中以“YYYY-MM-DD”格式获取当前日期?
- asp.net-mvc-3 – html.dropdownlist MVC3混乱
- asp.net – 将ControlParameter添加到SqlDataSource可以防止
- 编辑并在ASP.NET Web项目中继续
- asp.net – 创建没有ASMX文件的Web服务?
- CompTIA PK0-003 认证
推荐文章
站长推荐
热点阅读