【发布时间】:2014-11-16 06:42:18
【问题描述】:
当我搜索This Link to JSON file 时,它不会返回任何内容(resultCount = 0)。这是我正在尝试做的一些代码。
NSData *data = [[NSData alloc] initWithContentsOfURL:@"https://itunes.apple.com/search?term=EMINEMLFLOCKAFLOCKA&entity=song&limit=3" options:NSDataReadingUncached error:&error];
NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSString *resultCount = [JSON valueForKey:@"resultCount"];
// Does not return anything
NSLog(@"%@", resultCount);
我不明白为什么 resultCount 不返回任何内容。这段代码不存储它的值(0)吗?如何从 resultCount 中检索数据?我正在尝试从中获取 0、1、2 或 3 之类的值。
【问题讨论】:
-
“resultCount 不返回任何内容”是什么意思?
resultCount是NSNumber(但您错误地将其用作NSString)。这不是一个函数。你希望它“回归”什么?如何? 您是否查看了此 URL 传递的 JSON 并意识到resultCount确实为 0? -
A) 你确认
data是非空的吗? B) 你确认JSON是非空的吗? C) 你为什么不使用error参数? D) 为什么不向我们展示JSON中的值? -
@TheParamagneticCroissant 它显示数据中没有任何内容(如果 !data 的语句运行)。这是否意味着我无法获得 resultCount 值?
-
@abc123abc 表示
initWithContentsOfURL失败。检查什么是 interror。 -
如果
data中没有任何内容,那么error中就有内容。但你不会抛弃那个,是吗?
标签: ios objective-c json nsstring nsdata