[英]How to get JSON data parse from Arrays of dictionary iOS
list = ({
clouds = 24;
speed = "4.31";
temp = {
day = "283.84";
eve = "283.84";
night = "283.84";
};
}),
请谁能告诉我我在做什么错-我想先在表中显示list-> temp-> day值,我试图在要终止的数组中获取数据。 这是我的代码,我做错了什么
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:dataBuffer options:-1 error:nil];
NSLog(@"%@",json);
NSMutableDictionary * list = [json objectForKey:@"list"];
NSMutableArray *arrays = [[NSMutableArray alloc]initWithCapacity:0];
for (NSDictionary *lists in [list allValues]) {
[arrays addObject:[list valueForKey:@"temp"]];
}
如果要访问日期,请使用下面的行,
NSString *day = [json valueForKeyPath:@"list.temp.day"];
您的列表是一个数组,因此,如果您希望在不做太大改变的情况下进行操作,则可以替换为:
NSMutableDictionary * list = [json objectForKey:@"list"];
附:
NSMutableDictionary * list = [[json objectForKey:@"list"] objectAtIndex:0];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.