我正在尝试解析一些json,到目前为止我有:
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSDictionary *results = [json objectForKey:@"d"];
NSString *error = [results objectForKey:@"error"];
NSArray *items = [results objectForKey:@"vehicles"];
NSLog(@"items::%@", items);
for (NSDictionary *item in items) {
IDCard *idcard = [[IDCard alloc] init];
idcard.year = [item objectForKey:@"year"];
idcard.make = [item objectForKey:@"make"];
idcard.model = [item objectForKey:@"model"];
项目的 nslog 是这样的:
items::(
(
{
make = CHEV;
model = MALIBU;
year = 2002;
},
{
make = GMC;
model = SIERRA1500;
year = 1995;
}
)
)
它很好,直到它到达idcard.year = [item objectForKey:@"year"];
并且它崩溃了Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x9fdea80'
,我不明白它为什么这样做。
如果发布完整的 json 有帮助,请告诉我,我会的。谢谢你能给我的任何帮助。