简体   繁体   中英

problem in parsing JSON response in iphone

i am getting json data from this link

now i want data from "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

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

Check if resultarr and di really contains anything or not.

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

Check the viewer and set the values accordingly. [di objectForKey:@"legs"] returns an array. the first object of that array is a dictionary which has the key steps. But that too returns another array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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