无法解析来自Google的json响应 [英] unable to parse json response from google
本文介绍了无法解析来自Google的json响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试解析该网址.我已经使用了SBJsonParser,MTJSON和另一个解析器,但是在这三种情况下我都得到了NULL.
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)
2011-12-09 16:59:01.226 MapWithRoutes[2523:207] dictionary=(null)
请给我一些建议
推荐答案
如果检查了您使用 JSONlint.com 所提供的网址, a>,并且JSON无效.因此任何库都无法解析.
Oke if checked the url you gave with JSONlint.com and the JSON is not valid. thus can not be parsed by any library.
如果您使用 JSONkit ,则可以为NSError
对象提供parse调用以查看结果错误:
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);
}
这篇关于无法解析来自Google的json响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文