简体   繁体   English

如何使用iOS SDK从ASMX Web服务获取和解析JSON?

[英]How to fetch and parse JSON from an ASMX Webservice using iOS SDK?

I have a ASMX - Web Service and wanted to request a result as JSON. 我有一个ASMX-Web服务,想要将结果请求为JSON。 Therefore I used Fiddler to send a POST-Request. 因此,我使用Fiddler发送POST请求。

Method: 方法:

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<string> AllProjects()
{
   List<ProjectData> pList = m_linqHelper.GetProjects(string.Empty).ToList();
   List<string> ProjectNames = pList.Select(p => p.ProjectName).ToList();
   return ProjectNames;
}

Fiddler POST-Request: Fiddler POST请求:

POST http://localhost:52225/MyWebService.asmx/AllProjects HTTP/1.1
Content-Type: application/json
Host: localhost:52225
Content-Length: 0
Connection: Keep-Alive

As the result I got a string like: 结果,我得到一个像这样的字符串:

{"d":["My_Project"]}

What bothers me is the "d": . 困扰我的是“ d” : How can I parse such a request using the iOS SDK? 如何使用iOS SDK解析此类请求?

Thanks in advance. 提前致谢。

I use ASMX webserices too. 我也使用ASMX webserices。 For my requests I have implemented the AFNeworking library available on GitHub to call Webservice. 根据我的要求,我已经实现了可在GitHub上使用的AFNeworking库来调用Webservice。

You can find help on the GitHub page. 您可以在GitHub页面上找到帮助。 Then, the webservice give me a JSON result. 然后,Web服务给我一个JSON结果。 So I convert it like that : 所以我这样转换:

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];

Where responseObject is the result of AFNetworking request. 其中responseObject是AFNetworking请求的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM