我试图解析包含JSON数据到一个NSDictionary使用SBJson 3.0.4一个NSString,但是当我这样做,我得到这个错误:SBJSON解析的NSString的NSDictionary
"WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate: -[__NSCFString JSONValue]: unrecognized selector sent to instance 0x6ab7a40"
至于我知道(这不是很远),我得到的JSON是有效的,所以我不知道为什么会发生这种情况。我的代码编译罚款太... 这就是:
NSString *tempURL = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?address=%@&sensor=true",userInput.text];
NSURL *url = [NSURL URLWithString:tempURL];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:30];
// fetch the JSON response
NSData *urlData;
NSURLResponse *response;
NSError *error;
// make the synchronous request
urlData = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
// construct a String around the Data from the response
NSString *data = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
NSDictionary *feed = [data JSONValue];
打印字符串'data'的值。将数据内容复制到JSONLint.com的工具中,并查看它是否为有效的JSON。让我们知道发生了什么。 – Jim 2012-02-23 19:52:33
它说,它是有效的 – 2012-02-23 20:07:46