1

我正在使用 Xcode 4.6。我从服务器获得了一个有效的 Json 字符串,其中单引号已正确转义。如果我从服务器上的字段中删除单引号,我不会收到任何错误。

这是json字符串:

jsonStr: '{ "status": 0, "message": "success", "object": [ { "currentthreatlevelname": "Guarded", "devicename": "Virendra\'s Pad", "threatlevelname": null, "enabled": false, "practicemode": false, "locationname": null, "currentthreatlevel": 3, "status": 0, "deviceid": "APLFC8C49AF-D4DF-4AE0-9E7B-D2A3E94ED387", "threatlevel": null, "location": null } ], "site": "s2 security" }'

由。。。生产

NSString* jsonStr = [[NSString alloc] initWithData:_receivedData encoding:NSUTF8StringEncoding];

这里的解析代码是:

NSDictionary *d = [NSJSONSerialization JSONObjectWithData: _receivedData
              options:NSJSONReadingMutableContainers|NSJSONReadingAllowFragments
                                                error:&jsonError];

请帮忙。谢谢。

4

1 回答 1

2

转义 "Virendra\'s Pad" 中的单引号会使 JSON 无效。尝试删除反斜杠。

于 2013-03-13T18:39:50.770 回答