【发布时间】:2013-08-13 15:14:04
【问题描述】:
我正在尝试在此 URL 解析 JSON 文件:http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22YHOO%22%2C%22AAPL%22%2C% 22GOOG%22%2C%22MSFT%22)%0A%09%09&format=json&diagnostics=true&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=results
我目前的代码如下:
NSData *data=[NSData dataWithContentsOfURL:[[NSURL alloc] initWithString:url]];
NSError *error = nil;
id myJSON = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
NSLog(@"%@", error);
NSArray *jsonArray = (NSArray *)myJSON;
for (id element in jsonArray) {
NSLog(@"Element: %@", [element description]);
}
这段代码似乎每次都出现错误(ERROR 3840 "The operation could not be completed. (Cocoa error 3840.)" (JSON文本没有以数组或对象开头,并且允许片段未设置的选项.)").
我想知道这是否与我下载/解析数据的方式有关,或者是否是实际 JSON 中的问题,我必须以不同的方式处理它。
【问题讨论】:
标签: iphone json connection nsdata