2016-02-05 60 views
0

获取单个键的值我有一本字典的我想获得“身份证”IOS:如何从字典

{ 
    "procedures": [5950] 
    0: { 
    "Procedures": { 
        "id": "1" 
        "procedure_name": "3d render w/o postprocess" 
        "procedure_code": "76376" 
       } 
     } 
    1: { 
     "Procedures": { 
     "id": "2" 
     "procedure_name": "3d rendering w/postprocess" 
     "procedure_code": "76377" 
} 

所有我想要得到的值的值,它是在形式“ID” 我如何得到这个值

的我把下面的代码

NSString *post = @"api_key=............"; 
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 

NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]]; 

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; 
[request setURL:[NSURL URLWithString:@"http:........"]]; 

[request setHTTPMethod:@"POST"]; 
[request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
[request setHTTPBody:postData]; 

NSURLResponse *response; 
NSError *err; 
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err]; 

NSDictionary *dict6 = [self cleanJsonToObject:responseData]; 
+0

PLZ给一些更多的信息.​​..你希望所有的ID或特定的ID? –

+0

是的,我只想要字典形式的ID –

+0

你能显示你的完整回复.... –

回答

0

,因为它是嵌套的NSDictionary试试这个代码。

[[[dict6 objectForKey:@"0"] objectForKey:@"Procedures"] objectForKey:@"id"]; 
+0

它给出空输出 –

1

尝试下面的代码..

NSArray *ids = [[dict6 objectForKey:@"procedures"] valueForKeyPath:@"Procedures.id"]; 

NSArray *ids = [[dict6 objectForKey:@"procedures"] valueForPath:@"id"]; 
+0

相同的结果不起作用 –

+0

检查“dict6”不为空 –

+0

它给出的结果,但我没有找到确切的结果 –