如何使用NSDictionary
索引编号获取JSON条目?
JSON响应:
{
"data": {
"first": [{
"07:30": "Entry 1"
}, {
"09:05": "Entry 2"
}, {
"10:40": "Entry 3"
}],
},
"success": true
}
Xcode(AFnetworking):
[manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSMutableArray *myArray = [responseObject objectForKey:@"data"];
// OK, as NSDictionary have objectForKey.
NSLog (@"%@", [myArray objectAtIndex:1] );
// Error ;(
}];
答案 0 :(得分:3)
试试这个
[manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSArray *myArray = [[responseObject objectForKey:@"data"] objectForKey:@"first"];
NSLog (@"%@", [myArray objectAtIndex:1] );
}];
你有类似下面的内容
{ //<---- Dictionary
"data": { //<---- Dictionary
"first": [ //<---- Array
{ //<---- Dictionary
"07:30": "Entry 1"
}, {
"09:05": "Entry 2"
}, {
"10:40": "Entry 3"
}],
},
"success": true
}