【发布时间】:2019-09-21 11:24:55
【问题描述】:
Authorize.net 的沙盒 API 响应的 body 是:
{
"messages": {
"resultCode": "Error",
"message": [
{
"code": "E00012",
"text": "You have submitted a duplicate of Subscription 5777085. A duplicate subscription will not be created."
}
]
}
}
但是当我去解析它时:
try {
bodyObj = JSON.parse(body);
} catch (ex) {
console.error(ex);
}
我收到此错误:
SyntaxError: JSON 中位置 0 的意外标记
还有这个:console.log(response.headers['content-type']);
返回:application/json; charset=utf-8
我做错了什么?我想把 JSON 解析成一个 JS 对象。
【问题讨论】:
-
您的代码不能证明您声称的内容,因此至少在该 try 块之前添加一个
console.log(body),这样您就可以向自己证明body包含您认为/声称的内容.
标签: node.js json response authorize.net