简体   繁体   中英

unable to parse json response from google

I am trying to parse Json response from This URL . I have used SBJsonParser, MTJSON and another parser but i am getting NULL in all three case.

apiUrlStr = @"http://maps.google.com/maps?output=dragdir&saddr=Delhi&daddr=Mumbai+to:hyderabad";
NSURL* apiUrl = [NSURL URLWithString:apiUrlStr];
NSString *apiResponse = [NSString stringWithContentsOfURL:apiUrl encoding:NSUTF8StringEncoding error:nil];

SBJsonParser *json = [[[SBJsonParser alloc] init] autorelease];
NSDictionary *dictionary = [json objectWithString:apiResponse];
NSLog(@"dictionary=%@", [json objectWithString:apiResponse]);

2011-12-09 16:59:01.226 MapWithRoutes[2523:207] dictionary=(null)

Plz suggest me something

Oke if checked the url you gave with JSONlint.com and the JSON is not valid. thus can not be parsed by any library.

If you used JSONkit you can supply a NSError object with the parse call to see what went wrong:

NSError *error = nil;
NSDictionary *dictionary = [apiResponse objectFromJSONStringWithParseOptions:JKParseOptionNone error:&error]; 

if (!dictionary) {
   NSLog(@"Error: %@", error);
} 

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