【发布时间】:2011-12-16 15:55:27
【问题描述】:
我在我的数据库中读取信息我使用 JSON 但有异常
'NSInvalidArgumentException',原因:'-[NSCFString objectForKey:]:无法识别的选择器发送到实例 0x603dfb0'
我认为这部分:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *str = [[[NSString alloc] initWithData:buffer encoding:NSUTF8StringEncoding] autorelease];
NSArray *array = [str JSONValue];
if (!array)
return;
NSDateFormatter *fmt = [[[NSDateFormatter alloc] init] autorelease];
[fmt setDateFormat:@"yyyy-MM-dd"];
for (NSDictionary *dict in array) {
NSDate *d = [fmt dateFromString:[dict objectForKey:@"eve_date"]];
NSLog(@"%@",d);
[eventPHP addObject:[Events eventsNamed:[dict objectForKey:@"title_event"] description:[dict objectForKey:@"description"] date:d]];
}
}
【问题讨论】:
-
可能需要查看 json 字符串(或一个接近的示例)才能看到它的样子。另外尝试 valueForKey 而不是 objectForKey 作为测试(我认为它们的行为不同,但想看看)。
-
从另一个帖子中添加了一行,在我的回答中看起来相似。希望对您有所帮助。
-
错误消息说你正在发送
objectForKey,这是 NSDictionary 上的一个方法到一个 NSString。看起来你的类型不是你想象的那样。
标签: json nsstring nsdictionary