我正在使用Google API返回一些JSON,我已经使用JSON-framework (Stig B- Google Code)将其转换为Objective C类型。
我现在有了这样的结构:
responseData
results
[0]
title = "Stack Overflow"
cursor如何访问嵌套数组results来获取title值(我猜是字典)?
我试过了,但没有成功:
for (NSString *key in [jsonObjects objectForKey:@"responseData"]) {
NSLog(@"%@",key);
for (NSString *element in [key valueForKey:@"results"]) {
NSLog(@"%@",element);
}
}外部循环将打印出数组results和cursor的名称,这样就可以工作了,但是对于内部循环,我得到了一个not key value coding compliant错误。
谢谢
发布于 2010-01-12 20:51:38
您可以使用NSLog([jsonObjects description])查看字典的内容和结构。
要浏览到"results“数组及其内容,可以使用以下(或类似)代码:
NSDictionary* responseDict = [jsonObjects objectForKey:@"responseData"]; // Get your dictionary
NSArray* resultsArray = [responseDict objectForKey:@"results"];
for (NSDictionary* internalDict in resultsArray)
for (NSString *key in [internalDict allKeys])
NSLog([NSString stringWithFormat:@"%@ - %@", key, [internalDict objectForKey:key];https://stackoverflow.com/questions/2048595
复制相似问题