响应为 null 已创建 NsDictionary

Response is null Created NsDictionary

我有一个数组,我从中获取 NewsValue 下的摘要值

(
{
    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 in Dictionary .

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

他们给出的回复为 Null。

你一个人。你需要在这里写代码。

您收到了实际的字符串

"{\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,所以NS JSON序列化不会有丝毫机会来处理它)。

如果可能的话,去找那些在服务器上编写代码的人,他们会产生这些垃圾,并告诉他们发送正确的 JSON,而不是 JSON 包含带有数据的字符串以非标准格式。如果您做不到,您将不得不自己编写代码来完成这一切。

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