2015-10-13 128 views
0

我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"; 
} 

的字符串格式我想转换为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

它从哪里来? web服务 – Jamil

+0

如果我将您的“字符串”复制/粘贴到JSON验证器中,则不正确。你从哪里得到它?它似乎已经在NSDictionary格式。 – Larme

+0

检查jsonError给出的内容,并检查objectData是否为空 – Iftikhar

回答

0

这已经在JSON数据的词典合成。

所以你不需要转换。只需检索数据。

NSString * abstract = [Dic valueForKey:@"abstract"]; 
-1

请使用下面码

的NSData *目标数据= [[[tableDataArray objectAtIndex:indexPath.row] objectForKey:@ “NewsValue”] 的NSString * strResponce = [[NSString的页头]目标数据编码:NSUTF8StringEncoding ]。

NSMutableDictionary *dictResponse = [NSJSONSerialization JSONObjectWithData:[strResponce dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:&error]; 

如果([dictResponse isKindOfClass:[的NSMutableDictionary类]]){

的NSString * abstractStr = [dictResponse valueForKey:@ “抽象”];

}