大佬教程收集整理的这篇文章主要介绍了JSON Parse = > SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
const data = ["10093"]
const options = {
auth: userpsw,method: 'GET',CURLOPT_POSTFIELDS: data
};
const request = http.request(url,options,function(responsE) {
response.on("data",function(data){
console.log(JsON.parse(data));
})
})
@H_618_2@答案:
undefined:1
<br />
^
SyntaxError: Unexpected token < in JsON at position 0
at JsON.parse (<anonymous>)
@H_618_2@如果我不解析数据:
const request = http.request(url,function(data){
console.log(data);
@H_618_2@然后我得到以下按摩:
Buffer 3c 62 72 20 2f 3e 0a 3c 62 3e 57 61 72 6e 69 6e 67 3c 2f 62 3e 3a 20 20 69 6d 70 6c 6f 64 65 28 29 3a 20 49 6e 76 61 6c 69 64 20 61 72 67 75 6d 65 6e ... 282 more bytes
@H_618_2@我看不到什么?如何阅读答案?
var options = {
hostname: '_your_url',port: 'your_port',path: '/your_path',method: 'GET',json:true
}
request(options,function(error,response,body){
if(error) console.log(error);
else console.log(body);
});
,
@H_618_2@您的响应不是 JSON 格式,这就是您尝试解析响应时出错的原因,使用 try 和 catch 处理错误。以上是大佬教程为你收集整理的JSON Parse = > SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>)全部内容,希望文章能够帮你解决JSON Parse = > SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。