Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 字符串转换为字典_Ios_Objective C_Iphone - Fatal编程技术网

Ios 字符串转换为字典

Ios 字符串转换为字典,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

我有一个字符串格式的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 *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是否为空