2015-10-14 59 views
0

我有阵从中我得到抽象的价值是NewsValue响应为空创建的NSDictionary

(
{ 
    NewsId = 12; 
    NewsValue = "{\n abstract = \"Today P.M of India Mr. Narender Modi visited for the eve of Agarasen \\njayanti 
\\n\";\n created = 1444733102;\n imgUrl = \"\";\n nid = 12;\n title = \"Latest news\";\n}"; 
    Title = "Latest news"; 
} 
) 

我想下转换NewsValue在字典。

NSData *data = [[[tableDataArray objectAtIndex:indexPath.row]objectForKey:@"NewsValue"] dataUsingEncoding:NSUTF8StringEncoding]; 
     NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data 
                    options:kNilOptions 
                     error:&error]; 
     NSLog(@"%@",jsonResponse); 

他们给出的答复为空。

回答

2

你是你自己的。你需要在这里编写代码。

您收到实际字符串

"{\n abstract = \"Today P.M of India Mr. Narender Modi visited for the eve of Agarasen \\njayanti 
\\n\";\n created = 1444733102;\n imgUrl = \"\";\n nid = 12;\n title = \"Latest news\";\n}" 

本身包含一些不规范的格式(类似于JSON数据位,但绝对是 JSON,所以NSJSONSerialization不会有丝毫的机会来处理它)。

如果完全有可能,请转到编写垃圾代码的服务器上的代码,并告诉他们发送正确的JSON,而不是包含带有非标准格式数据的字符串的JSON。如果你不能这样做,你必须编写代码来完成这一切。

顺便说一句。这个字符串看起来很像NSLog为NSDictionary输出的内容。检查字符串来自哪里。也许有人在你自己的代码中做了一些愚蠢的事情。