所以我用C#和网络的东西,并试图找出东西出来一个完整的小白。有一些代码,这样说:NSJSONSerialization用C#REST服务
[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输出如下:
{ “分页”:{ “页面”:1, “总”:4440, “PAGE_SIZE”:20, “页”:222}, “贷”:[{ “ID”:447290, “名”:”罗莎 “ ”描述“:{ ”语言“:[ ”ES“, ”烯“]} ”状态“: ”筹款“, ”funded_amount“:0 ”basket_amount“:0, ”图像“:{” ID “:1134583”,template_id “:1},” 活动 “:” 动物销售”, “板块”: “农业”, “用”: “买稗鸡饲料”, “位置”:{ “COUNTRY_CODE” : “PE”, “国”: “秘鲁”, “镇”: “M \ u00f3rrope - 兰巴耶克”, “地理”:{ “级”: “国家”, “对”: “ - 10 -76”,”类型 “:” 点 “}},” PARTNER_ID “:143,” posted_date “:” 2012-07-13T19:00:05Z”, “planned_expiration_date”: “2012-08-12T19:00:05Z”, “loan_amount” :400, “borrower_count”:1},{ “ID”:447292,“呐
在iPad上,当我这样做:
NSDictionary *fields = [NSJSONSerialization JSONObjectWithData:response options:kNilOptions error:&error];
或
NSArray *fields = [NSJSONSerialization JSONObjectWithData:response options:kNilOptions error:&error];
两者都是空的。它是不是正确的JSON的C#的输出?谢谢。
您的Json字符串(以'AddressesCollection'开头)无效 – 2012-07-13 19:56:34
@ L.B那是因为JavaScriptSerializer吗? – Crystal 2012-07-13 21:38:58