我有一个JSON的String格式
{
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";
}
我想转换为NSDictionary
NSError *jsonError;
NSData *objectData = [[[tableDataArray objectAtIndex:indexPath.row]objectForKey:@"NewsValue"] dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:objectData options:NSJSONReadingMutableContainers error:&jsonError];
NSLog(@"%@",json);
他们回答是空的请帮助。
答案 0 :(得分:0)
这已经存在于字典格式的Json数据中。
所以你不需要转换。只需检索数据。
NSString * abstract = [Dic valueForKey:@"abstract"];
答案 1 :(得分:-1)
请使用以下代码
NSData * objectData = [[[tableDataArray objectAtIndex:indexPath.row] objectForKey:@" NewsValue"] NSString * strResponce = [[NSString alloc] objectData encoding:NSUTF8StringEncoding];
NSMutableDictionary *dictResponse = [NSJSONSerialization JSONObjectWithData:[strResponce dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:&error];
if([dictResponse isKindOfClass:[NSMutableDictionary class]]){
NSString * abstractStr = [dictResponse valueForKey:@" abstract"];
}