开发者

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 objectFo开发者_JAVA技巧rKey:@"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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜