在访问字典内容的时候失败:
`NSLog(@"self.userCommentsArray %@",self.userCommentsArray);返回null。
`
请帮忙:
NSData *jsonData = [NSData dataWithContentsOfURL:myURL];
NSDictionary *userCommentsDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
NSLog(@"userCommentsDictionary %@",userCommentsDictionary); // this works
self.userCommentsArray = [[userCommentsDictionary objectForKey:@"from"] objectForKey:@"name"];
NSLog(@"self.userCommentsArray %@",self.userCommentsArray);
这是dicitionary的NSlog输出:
userCommentsDictionary {
data = (
{
created = "2013-07-16T18:42:56+02:00";
from = {
id = 27;
name = "user-4";
};
id = 2553;
message = "liquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum";
},
{
created = "2013-07-16T18:42:56+02:00";
from = {
id = 28;
name = "user-5";
};
id = 2554;
message = "x ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum";
},
{
created = "2013-07-19T16:18:56+02:00";
from = {
id = 24;
name = "user-1";
};
id = 5125;
message = test comment;
},
{
created = "2013-07-19T17:00:21+02:00";
from = {
id = 24;
name = "user-1";
};
id = 5126;
message = "test comment ";
}
);
meta = {
totalCount = 18;
};
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。