gpt4 book ai didi

objective-c - NSMutableArray 中的错误

转载 作者:行者123 更新时间:2023-11-29 11:12:48 25 4
gpt4 key购买 nike

我是 ios 开发的新手,我正在尝试将一些值从 NSMutableDictionary 添加到 NSMutableArray,当我运行代码时出现此错误

2012-05-29 14:09:34.913 iShop[7464:f803] -[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x6e423d0 2012-05-29 14:09:34.915 iShop[7464:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x6e423d0' * First throw call stack: (0x13cb022 0x155ccd6 0x13cccbd 0x1331ed0 0x1331cb2 0x2bb7 0x13cce42 0x93b9df 0x139f94f 0x1302b43 0x1302424 0x1301d84 0x1301c9b 0x12b47d8 0x12b488a 0x15626 0x28bd 0x2825) terminate called throwing an exception(lldb)

下面是我的代码:

-(void) getData:(NSData *) response {
NSError *error;

NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:kNilOptions error:&error];
//NSLog(@"%@", json);

jsonArray = [[NSMutableArray alloc] init];

jsonArray = [json objectForKey:@"Name"];

NSLog(@"%@", jsonArray);

}

- (void)viewDidLoad {
[super viewDidLoad];

jsonURL = [NSURL URLWithString:@"http://localhost:8888/read_product_list.php"];
dispatch_async(BgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL:jsonURL];
[self performSelectorOnMainThread:@selector(getData:)
withObject:data waitUntilDone:YES];
});
}

最佳答案

JSONObjectWithData 返回类型为 id 的对象。取决于您收到的 json 数据的结构。收到的数据是 NSDictionaryNSArray。在你的情况下,我猜测顶级对象是 NSArray 类型,它不响应 objectForKey

关于objective-c - NSMutableArray 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10799111/

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