【发布时间】:2012-02-23 19:46:53
【问题描述】:
我正在尝试使用 SBJson 3.0.4 将包含 JSON 数据的 NSString 解析为 NSDictionary,但是当我这样做时,我收到此错误:
“WebKit 在 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。让我们知道会发生什么。
标签: objective-c json nsstring nsdictionary sbjson