从NSDictionary获取价值不起作用(get value from NSDictionary not work)
1.我从Web服务获取JSON数据并将其添加到NSDictionary
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];然后我在NSLog中显示“dic”它出现了
{"query": [{"IndexNo": 1,"ID": "01","Picture": "img/food-48.png"}]}然后我从“dic”获取数据值到新的NSDictionary“dt”
NSDictionary *dt = [dic objectForKey: @"query"];然后我在NSLog中显示“dt”它出现了
({ID = 01;IndexNo = 1;Picture = "img/food-48.png";})我想从“dt”获得“ID”。 我用这个代码
NSString *ID = [dt objectForKey: @"ID"];但这是错误的
-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x8a40a601.I get JSON data from web services and add It's to NSDictionary
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];2.Then I Show "dic" in NSLog It's present
{"query": [{"IndexNo": 1,"ID": "01","Picture": "img/food-48.png"}]}3.Then I get data value from "dic" in to new NSDictionary "dt"
NSDictionary *dt = [dic objectForKey: @"query"];4.Then I Show "dt" in NSLog It's present
({ID = 01;IndexNo = 1;Picture = "img/food-48.png";})5.I want to get "ID" from "dt". I use this code
NSString *ID = [dt objectForKey: @"ID"];but it's error
-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x8a40a60最满意答案
你能试试吗?
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error]; NSArray *arr = [dic objectForKey: @"query"]; NSDictionary *dt = arr[0]; NSString *ID = [dt objectForKey: @"ID"];Can you try this
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error]; NSArray *arr = [dic objectForKey: @"query"]; NSDictionary *dt = arr[0]; NSString *ID = [dt objectForKey: @"ID"];更多推荐
发布评论