我使用 JSON 但有例外 [NSString objectForKey:]
我在数据库中读取信息我使用 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]];
}
}
i read information in my database i use JSON but there is exception
'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance 0x603dfb0'
I think this part :
- (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]];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调整我的项目的构建设置以将此标志包含在“其他链接器标志”中
“向链接器传递一个特殊标志“-ObjC”。根据以下内容
: http://beatworm.co.uk/blog/computers/using-categories-on-objective-c-classes-in-a-static-library/
编辑:
为什么要终止?
编辑2:
好吧,不太确定(因为我从来没有做过这种类型的编码),但是考虑到 json 数据:
第一个对象是一个标记为“event”的数组,这可能会让你失望。
因此,尝试将其替换
为:
使用: 使用 JSONValue 获取 JSON 内容时出现问题
不确定这是否有效,但如果有效,对我来说会更有意义。
"pass the linker a special flag, ‘-ObjC’. Adjusting the build settings of my project to include this flag in the ‘Other linker flags’"
according to:
http://beatworm.co.uk/blog/computers/using-categories-on-objective-c-classes-in-a-static-library/
EDIT:
Why it is terminating?
EDIT2:
OK, not exactly sure (as I've never done this type of coding), but given the json data:
The first object is an array labeled "event" which might be throwing you off.
So, try replacing this:
with:
using: Problem getting JSON contents with JSONValue
Not sure if that will work, but if it does, it will make more sense to me.
我通过更改 JSON 的位置文件类解决了异常,但该事件未
显示在日历中。
日历已显示,但不包含任何事件
提示:当我将 url 输入浏览器时,数据库显示的内容
I solve exception by change location files class of JSON but the event doesn't
display in calendar .
the calendr is display but didn't contain any event
hint: when i put url in browser the content of database display