所以我是一个完全的 C# 和网络东西的菜鸟,并试图弄清楚一些事情。有一些代码是这样说的:
[WebInvoke(UriTemplate = "People", Method = "GET", ResponseFormat = WebMessageFormat.Json)]
public string GetPeople() {
Person results = DataAccess.ParsePeople();
System.WebScrip.Serialization.JavaScriptSerializer oSerializer = oSerializer.MaxJsonLength = int.MaxValue;
string sJSON = oSerializer.Serialize(results);
return sJSON;
}
当我输入此方法的 url 时,我的响应如下所示:
"{\"AddressesCollection\":[{\"Street\":\"1234 Temp Dr\",\"Zip\":94011},{\"Street\":\"56789 Nothing Dr\",\"Zip\":2222},\"ErrorMessage\":\"SUCCESS\"}"
我试图在 iPad 端遵循本教程:http ://www.raywenderlich.com/5492/working-with-json-in-ios-5
查看他们用作示例的网站,JSON 输出如下所示:
{"paging":{"page":1,"total":4440,"page_size":20,"pages":222},"loans":[{"id":447290,"name":"Rosa" ,"description":{"languages":["es","en"]},"status":"fundraising","funded_amount":0,"basket_amount":0,"image":{"id": 1134583,"template_id":1},"activity":"Animal Sales","sector":"Agriculture","use":"购买稗鸡和饲料。","location":{"country_code":" PE","country":"Peru","town":"M\u00f3rrope - Lambayeque","geo":{"level":"country","pairs":"-10 -76","type" :"点"}},"partner_id":143,"posted_date":"2012-07-13T19:00:05Z","planned_expiration_date":"2012-08-12T19:00:05Z","loan_amount":400,"借款人计数":1},{"id":447292,"na
在 iPad 上,当我这样做时:
NSDictionary *fields = [NSJSONSerialization JSONObjectWithData:response options:kNilOptions error:&error];
或者
NSArray *fields = [NSJSONSerialization JSONObjectWithData:response options:kNilOptions error:&error];
两者都是空的。是不是正确的 JSON 的 C# 输出?谢谢。