我从我的 wcf 服务中获得了这个结果 JSON,我想在我的 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"
}
]
}
最佳答案
试试这个:
NSArray *result=[dictionary valueForKey:@"ListTopReportsResult"];
因为在您的 JSON 中,有一个用于键 ListTopReportsResult
的数组。
希望这对您有所帮助。 :)
关于ios - Objective C 解析 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25503943/