[英]IOS: how to get the value of a single key from dictionary
I have a dictionary which is in the form of I want to get the value of "id" 我有一个字典,该字典的形式是我想获取“ id”的值
{
"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"
}
all I want to get the value of "id" how I get this value 我想要获取“ id”的值的所有方式
I put the following code 我把下面的代码
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];
Try following code.. 尝试以下代码。
NSArray *ids = [[dict6 objectForKey:@"procedures"] valueForKeyPath:@"Procedures.id"];
or 要么
NSArray *ids = [[dict6 objectForKey:@"procedures"] valueForPath:@"id"];
请尝试将此代码嵌套NSDictionary。
[[[dict6 objectForKey:@"0"] objectForKey:@"Procedures"] objectForKey:@"id"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.