[英]valid json string but cannot parse
my environment is nodejs我的环境是 nodejs
let z = await x.text();
console.log(z)
let y = JSON.parse(z)
the console log is控制台日志是
{
"errorCode":0,
"errorMsg":"success",
"result":{
"msg":"\u4e70\u5bb6\u5df2",
"uid":"104",
"username":"\u738b\u626d",
"userphone":"1565777778",
"address":"\u4e0a\u6d77",
"price":"5.00",
"trade_state":"TRADE_SUCCESS",
"hk_orderid":"1575524694820"
}
}
(node:21) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token in JSON at position 0
(node:21) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token in JSON at position 0
when I copy the json string and paste it to当我复制 json 字符串并将其粘贴到
JSON.parse('{"errorCode":0,"errorMsg":"success","result":{"msg":"\u4e70\u5bb6\u5df2","uid":"104","username":"\u738b\u626d","userphone":"1565777778","address":"\u4e0a\u6d77","price":"5.00","trade_state":"TRADE_SUCCESS","hk_orderid":"1575524694820"}}')
inside browser console浏览器控制台内
the parsing is correct解析正确
edit: someone asks about the json, actually the json is exactly what I pasted above编辑:有人询问json,实际上json正是我上面粘贴的
{
"errorCode":0,
"errorMsg":"success",
"result":{
"msg":"\u4e70\u5bb6\u5df2",
"uid":"104",
"username":"\u738b\u626d",
"userphone":"1565777778",
"address":"\u4e0a\u6d77",
"price":"5.00",
"trade_state":"TRADE_SUCCESS",
"hk_orderid":"1575524694820"
}
}
this is also the output of console.log(z)这也是 console.log(z) 的输出
below are some further logs, note that only the last one has an exception下面是一些进一步的日志,注意只有最后一个有异常
processing job id 19121211173822287103
12/12/2019 12:17:45 PM {"errorCode":0,"errorMsg":"success","result":{"msg":"\u7b49\u5f85\u8cb7\u5bb6\u4ed8\u6b3e","uid":"103","username":"\u674e\u767d","userphone":"18912345678","address":"\u7ef4\u4e5f\u7eb3\u9152\u5e97(\u77f3\u82b1\u897f\u8def\u5e97)","price":"4.00","trade_state":"WAIT_BUYER_PAY","hk_orderid":"1576120657890"}}
12/12/2019 12:17:50 PM processing job id 19121211173822287103
12/12/2019 12:17:50 PM {"errorCode":0,"errorMsg":"success","result":{"msg":"\u7b49\u5f85\u8cb7\u5bb6\u4ed8\u6b3e","uid":"103","username":"\u674e\u767d","userphone":"18912345678","address":"\u7ef4\u4e5f\u7eb3\u9152\u5e97(\u77f3\u82b1\u897f\u8def\u5e97)","price":"4.00","trade_state":"WAIT_BUYER_PAY","hk_orderid":"1576120657890"}}
12/12/2019 12:17:55 PM processing job id 19121211173822287103
12/12/2019 12:17:57 PM
12/12/2019 12:17:57 PM {"errorCode":0,"errorMsg":"success","result":{"msg":"\u4e70\u5bb6\u5df2\u652f\u4ed8","uid":"103","username":"\u674e\u767d","userphone":"18912345678","address":"\u7ef4\u4e5f\u7eb3\u9152\u5e97(\u77f3\u82b1\u897f\u8def\u5e97)","price":"4.00","trade_state":"TRADE_SUCCESS","hk_orderid":"1576120657890"}}
12/12/2019 12:17:57 PM (node:21) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token in JSON at position 0
12/12/2019 12:17:57 PM at JSON.parse (<anonymous>)
12/12/2019 12:17:57 PM at /usr/src/app/routes/notify.js:39:26
可能需要查看更多代码,因此如果您从服务器/url 中提取 JSON,请确保响应标头将此显示为 JSON 数据类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.