{ ValidationError: { device_uuid: [ [Object] ] } }
我喜欢将这个字符串转换成 JSON 格式,就像这样
{ "ValidationError": { "device_uuid": [ [Object] ] } }
无论如何,我是否可以从格式错误的 JSON 字符串中得到这个结果?
最佳答案
假设您确定格式不正确的字符串是安全的并且只是格式错误的 JSON(即不会执行任何其他 javascript),您可以先 eval 然后 JSON.stringify 。
JSON.stringify(eval('(' + myString + ')'));
关于javascript - 解析没有双引号的格式错误的 json 字符串(Java 脚本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20084489/