首先看看我的json文件,如下所示:
[
{
id: 1
arr: {
name: "功夫"
sex: "m"
age: 40
}
GP: [
{
Peter: 32
}
]
}
]我使用JSONKit分析这个文件。就像下面的代码
JSONDecoder *jsonDec = [[[JSONDecoder alloc] initWithParseOptions:JKParseOptionNone] autorelease];
dic = [jsonDec objectWithData:data];
if (dic == nil) {
NSLog(@"dic is nil !!!!!!!!!");
return;
}
NSLog(@"%d..",[dic count]);
NSLog(@"%@",dic);
if (dic != nil) {
for (id ary in dic) {
NSLog(@"kkkkkk %@",[ary objectForKey:@"arr"]);
}
for (id key in dic)
{
NSLog(@"key: %@ ,value: %@",key,[dic objectForKey:key]);
//this line error.
}
}当运行时,它会崩溃。
2011-07-28 19:24:27.499 MyJSONTest[27274:207] -[JKArray objectForKey:]: unrecognized selector sent to instance 0x692ee40
2011-07-28 19:24:27.500 MyJSONTest[27274:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[JKArray objectForKey:]: unrecognized selector sent to instance 0x692ee40'我需要帮助,谢谢大家。
发布于 2011-07-28 20:11:53
看起来你运行的代码并不知道JKArray有一个objectForKey:函数。
但是你确定JKArray有一个objectForKey:吗?您是否在考虑JKDictionary
NSDirectory使用密钥运行,而NSArrays使用objectatindex:
检查你的文件头。您是否包含了正确的文件?如果你想使用NSObject功能,添加@Class头是不够的,不够。
https://stackoverflow.com/questions/6858223
复制相似问题