gpt4 book ai didi

ios - 解析 JSON 时无法识别的选择器

转载 作者:行者123 更新时间:2023-11-28 19:52:28 25 4
gpt4 key购买 nike

下面的照片是我尝试从 URL 读取的 JSON 脚本的屏幕截图。在下面的代码部分,我设法获取了“name”属性并将其分配给“name”NSString 对象,但是当我尝试对“address”执行相同操作时,出现以下错误:

[__NSCFDictionary objectAtIndexedSubscript:]: unrecognized selector sent to instance 0x174260980
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndexedSubscript:]: unrecognized selector sent to instance 0x174260980'

我在“场所”内的操作方式与在“位置”内的操作方式有何区别?我尝试了很多不同的方法来做到这一点,有些包括数组,但似乎没有任何效果。

enter image description here

NSURL *url = [NSURL URLWithString:urlString];

NSData *jsonData = [NSData dataWithContentsOfURL:url];
NSError *error = nil;
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];

NSDictionary *responseDictionary = [dataDictionary objectForKey:@"response"];
NSDictionary *venueDictionary = [responseDictionary objectForKey:@"venues"];

for (NSDictionary *dict in venueDictionary) {
NSLog(@"%@", dict);
NSString *name = [dict objectForKey:@"name"];
NSDictionary *locationDictionary = [dict objectForKey:@"location"];
for (NSDictionary *locationDict in locationDictionary) {
NSString *address = [locationDict objectForKey:@"address"];
NSLog(@"%@", address);
}
}

最佳答案

您期望“location”键指向一个数组,但事实并非如此。它指向一个对象,摆脱 for (NSDictionary *locationDict in locationDictionary) { 并只是从 locationDictionary 中提取地址。

关于ios - 解析 JSON 时无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28446564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com