我有一个数组,我从中获得了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";
}
)
我想在Dictionary中转换NewsValue。
NSData *data = [[[tableDataArray objectAtIndex:indexPath.row]objectForKey:@"NewsValue"] dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&error];
NSLog(@"%@",jsonResponse);
他们给予回应Null。
答案 0 :(得分: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输出的内容。检查字符串的来源。也许有人在你自己的代码中做了一些愚蠢的事情。