简体   繁体   English

iPhone中解析JSON响应时出现问题

[英]problem in parsing JSON response in iphone

i am getting json data from this link 我正在从此链接获取json数据

now i want data from "html_instructions": part 现在我要从“ html_instructions”中获取数据:part

NSDictionary *result = [stringtext JSONValue];
NSLog(@"here");
NSArray *resultarr = [result objectForKey:@"routes"];
NSString *string;

for(NSDictionary *di in resultarr){
    NSLog(@"for loop");
    string = [[di objectForKey:@"legs"] objectForKey:@"steps"];
}

but after printing "for loop" in console it is throwing an exception 但是在控制台中打印“ for loop”后,它将引发异常

2011-05-20 16:16:26.997 speedymap[759:207] -[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x62a7d60

2011-05-20 16:16:26.999 speedymap[759:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x62a7d60'

please help me i want html_instructiuons field value 请帮我,我想要html_instructiuons字段值

Check if resultarr and di really contains anything or not. 检查resultarrdi真的包含任何东西。

NSDictionary *result = [stringtext JSONValue];
NSLog(@"here");
NSArray *resultarr = [result objectForKey:@"routes"];
CFShow(resultarr);
NSString *string;

for(NSDictionary *di in resultarr){
    CFShow(di);
    NSLog(@"for loop");
    NSArray *tempArr = [[di objectForKey:@"legs"] objectForKey:@"steps"];
}

http://jsonviewer.stack.hu/#http://maps.googleapis.com/maps/api/directions/json?origin=delhi&destination=noida&waypoints=&sensor=true http://jsonviewer.stack.hu/#http://maps.googleapis.com/maps/api/directions/json?origin=delhi&destination=noida&waypoints=&sensor=true

Check the viewer and set the values accordingly. 检查查看器并相应地设置值。 [di objectForKey:@"legs"] returns an array. [di objectForKey:@“ legs”]返回一个数组。 the first object of that array is a dictionary which has the key steps. 该数组的第一个对象是具有关键步骤的字典。 But that too returns another array. 但这也返回另一个数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM