JSON.parse: expected property name or '}'

2019-01-23 23:02发布

Data contains (/"/):

 {"test":"101","mr":"103","bishop":"102"}

script:

console.log($.parseJSON(result));

I'm getting error,

JSON.parse: expected property name or '}'.

标签: json parsing
2条回答
Viruses.
2楼-- · 2019-01-23 23:19

Had same issue when used single quotes in JSON file, changed to double quotes for all string properties/values and it's working OK now, hope it helps anyone....

Change:

JSON.parse("{'wrongQuotes': 5}") 

To:

JSON.parse('{"rightQuotes": 5}')
查看更多
Deceive 欺骗
3楼-- · 2019-01-23 23:21

If you're receiving the JSON with the encoded ", you'll have to replace each instance of " with a true " before doing JSON.parse. Something like:

myJSONstring.replace(/"/ig,'"');
查看更多
登录 后发表回答