我从服务器获取此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);
答案 0 :(得分:0)
更改为:
'{"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>