我正在尝试NSJSONSerialization
使用下面的代码输出一些数据。
此日志语句有效 NSLog(@"publicData: %@", publicData);
,但是当我尝试获取字典的“描述”时它崩溃了 NSLog(@"data: %@", [dict objectForKey:@"description"]);
我的错误信息:unrecognized selector sent to instance. Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance...'
我已经包含了NSLog
输出。
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL
URLWithString:@"http://******.com/api/feed"]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSError *jsonParsingError = nil;
NSArray *publicData = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError];
NSLog(@"data from publicData: %@", publicData);
NSDictionary *dict;
for(int i=0; i<[publicData count];i++)
{
dict= [publicData objectAtIndex:i];
NSLog(@"data: %@", [dict objectForKey:@"description"]);
}
publicData: {
data = (
{
address = {
address = "street address";
city = cityname;
lat = "42.000237034667";
lng = "12.492805660226";
province = provincename;
};
"category_id" = 20;
description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum";
id = 1;
slug = "title-in-en";
title = "title in En";
},
{
address = {
address = "street address";
city = cityname;
lat = "42.000237034667";
lng = "12.492805660226";
province = provincename;
};
"category_id" = 20;
description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum";
id = 5;
slug = "title-in-en";
title = "title in En";
},
谢谢你的帮助