Ios 字符串转换为字典
我有一个字符串格式的JSONIos 字符串转换为字典,ios,objective-c,iphone,Ios,Objective C,Iphone,我有一个字符串格式的JSON { abstract = "Today P.M of India Mr. Narender Modi visited for the eve of Agarasen \njayanti \n"; created = 1444733102; imgUrl = ""; nid = 12; title = "Latest news"; } 我想转换成一本字典 NSError *jsonError; NSData *objectD
{
abstract = "Today P.M of India Mr. Narender Modi visited for the eve of Agarasen \njayanti
\n";
created = 1444733102;
imgUrl = "";
nid = 12;
title = "Latest news";
}
我想转换成一本字典
NSError *jsonError;
NSData *objectData = [[[tableDataArray objectAtIndex:indexPath.row]objectForKey:@"NewsValue"] dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:objectData options:NSJSONReadingMutableContainers error:&jsonError];
NSLog(@"%@",json);
他们给出的响应为空,请帮助。这已经存在于字典格式的Json数据中 所以你不需要转换。只需检索数据
NSString * abstract = [Dic valueForKey:@"abstract"];
请使用下面的代码 NSData*objectData=[[tableDataArray objectAtIndex:indexPath.row]objectForKey:@“NewsValue”] NSString*strresponse=[[NSString alloc]对象数据编码:NSUTF8StringEncoding]
NSMutableDictionary *dictResponse = [NSJSONSerialization JSONObjectWithData:[strResponce dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:&error];
if([dictResponse IsKindof类:[NSMutableDictionary类]]){
NSString*abstractStr=[dictResponse valueForKey:@“abstract”]
}它来自何处?web服务如果我将您的“字符串”复制/粘贴到JSON验证器中,则不正确。您从何处获得它?它似乎已经是NSDictionary格式。请检查jsonError给出的内容,并检查objectData是否为空