jQuery.parseJSON给出错误意外标记

jQuery.parseJSON giving error unexpected token

本文关键字:意外 错误 出错 parseJSON jQuery      更新时间:2023-09-26

我正在从服务器获取此JSON

"{"name": "abcd,e"abc"ssfgh", "location": {"latitude": 21.1484436189,"longitude": 79.093036862},"id": "12345"}"

我知道这个JSON中的问题是名称值中的(")。但问题是我无法更改JSON(因为我是从服务器上得到的)。那么现在如何解析它呢?我想将这个JSON字符串转换为对象。

jQuery.parseJSON出现错误。

编辑:

以下是我正在做的解析这个JSON字符串的操作var body_json=jQuery.parseJSON(JSONString);

更改如下:

'{"name": "abcd,e''abc''ssfgh", "location": {"latitude": 21.1484436189,"longitude": 79.093036862},"id": "12345"}'

**关注'''{}'**

var str = '{"name": "abcd,e''abc''ssfgh", "location": {"latitude": 21.1484436189,"longitude": 79.093036862},"id": "12345"}';
var json = jQuery.parseJSON(str);
$('div').text(json);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div>123</div>