![](/img/trans.png)
[英]How To Get Particular Values From JSON and Plot on Map view Using Objective C?
[英]How To Get Particular Values From Json Response Using Objective C?
我试图获得first key
response
,而没有使用objective C
提及键名"A"
。 我无法完全了解,请帮助我从以下回复中获取帮助。
NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves | NSJSONReadingMutableContainers error:&error];
NSDictionary *response = [JSON[@"response"]firstObject];
response = {
A = {
company = (
{
no = "115";
student = "Mich";
school = (
{
grade = A;
}
);
test = "<null>";
office = tx;
}
);
};
}
有几种方法可以执行此操作,具体取决于您的确切要求。 如果您只需要访问JSON[@"response"]
中每个键的值,则可以枚举JSON
字典:
[JSON enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
NSDictionary *dict = (NSDictionary *)obj;
...
if (shouldStop) { // whatever condition you want, if any
*stop = YES;
}
}];
如果需要某种排序,则需要使用[JSON allKeys]
:
NSArray *keys = [[JSON allKeys] sortedArrayUsing...]; // Use whichever sort method you like
for (NSString *key in keys) {
NSDictionary *dict = JSON[key];
...
}
如果只需要这些值,则可以使用[JSON allValues]
。 如果需要,排序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.