【发布时间】:2016-11-08 02:39:36
【问题描述】:
如何提取JSON 数据dictionary。我尝试了很多次,但无法提取特定的价值。我只得到第一个“business_category_name”,但值“name”下的“business_details”无法获取。怎么可能请帮忙。
谢谢
我的 JSON 数据
{
"status": [
{
"business_category_name": "Banks\/Credit Unions\/Landers",
"business_details": [
{
"img_url": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/member-logo\/1464667619-pnc.jpg",
"name": "PNC Bank",
"des": "PNC offers a wide range of services for all our customers, from individuals and small businesses, to corporations and government entities",
"address": "",
"email": "andrea.kendall@pnc.com",
"phone": "260-422-5922",
"member_since": "2016-05-31",
"img_company": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/member-logo\/1464667619-pnc.jpg",
"website": "",
"city": "Fort Wayne",
"state": "IN",
"zip": "46808"
}
]
},
{
"business_category_name": "Cleaning Services",
"business_details": [
{
"img_url": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/uploads\/logo250.png",
"name": "tsst company",
"des": "rudurgg ",
"address": "2005 s calhoun ",
"email": "",
"phone": "2602496687",
"member_since": "2016-05-31",
"img_company": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/uploads\/logo250.png",
"website": "",
"city": "fort wayne",
"state": "in",
"zip": "46825"
}
]
}
]
}
我的代码
- (void)viewDidLoad {
[super viewDidLoad];
NSURLRequest *req=[[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"my url"]];
response =[[NSMutableData alloc]init];
[NSURLConnection connectionWithRequest:req delegate:self];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;
NSLog(@"Error in receiving data %@",error);
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSLog(@"response data %@",json);
NSArray *items = [json objectForKey:@"status"];
pass = [items valueForKey:@"business_category_name"];
NSLog(@"get category %@",pass);
}
【问题讨论】:
-
为了更方便,你可以创建一个模型类。
标签: ios objective-c json parsing nsarray