【发布时间】:2014-08-26 10:47:39
【问题描述】:
我有这个结果 JSON 下面是我从我的 wcf 服务获得的,我想在我的 ipad 应用程序中迭代它。我使用下面的代码来解析结果 json,但应用程序给出了错误。如何遍历这个字典并获取项目。
IOS代码:
myArray = [NSMutableArray array];
// Do any additional setup after loading the view.
NSString* URL = @"http://www.unluapps.com/Service1.svc/ListTopReports";
NSDictionary *dictionary = [JSONHelper loadJSONDataFromURL:URL ];
NSString *result=[dictionary valueForKey:@"ListTopReportsResult"];
NSLog(@"%@",result);
/* for (NSString* key in result ) {
id value=[result objectForKey:key];
NSLog(@"%@ -+",value);
}
*/
JSON:
{
ListTopReportsResult: [
{
AppUserID: null,
Author: "Joe Matthew",
Company: "Coca-Cola",
Country: "Poland",
CreationDate: "8/20/2014 4:32:00 AM",
EndDate: null,
ResearchReportID: "2",
Sector: "Soft Drinks",
Summary: "da ascon casmld lmasdlasd",
Title: "Can Coca-cola beat the market?",
URL: "2123123.pdf"
},
{
AppUserID: null,
Author: "martina pawlik",
Company: "Cimsa",
Country: "Poland",
CreationDate: "8/20/2014 4:31:00 AM",
EndDate: null,
ResearchReportID: "1",
Sector: "Cement",
Summary: "asd adas asd asdasd asdasdasd",
Title: "Poland's cement sector is on the rise",
URL: "1123123.pdf"
}
]
}
【问题讨论】:
-
result应该是NSArray,而不是NSString。 -
这可以帮助你 NSArray *yourArray=[dictionary valueForKey:@"yourKey"];
标签: ios asp.net objective-c json wcf