Uncaught (in promise) SyntaxError: "[object Object]" is not valid JSON
中文为:
未捕获(承诺中)语法错误:“[object Object]”不是有效的 JSON
后台返回的数据虽然是 json
字符串的样式,但是通过 json.parse()
方法一直解析不出来;
应该是返回的字符串的数据不正确,可能多了一些不必要的符号等情况;
其一、可能多了一些不必要的回车:
A、数据格式为:
'{
"switch": "true",
"version": "RSTP",
"age": "20",
"delay": "15",
"count": "6",
"hops": "20",
"mstName": "name",
"matRevision": "1",
}'
B、数据展示为:
其二、可能多了一些不必要的逗号(如:多了最后一个逗号就报错):
A、数据格式为:
'{"switch": "true","version": "RSTP","age": "20","delay": "15","count": "6","hops": "20","mstName": "name","matRevision": "1",}'
其三、可能多了一些不必要的双引号:
A、数据格式为:
"'{"switch": "true","version": "RSTP","age": "20","delay": "15","count": "6","hops": "20","mstName": "name","matRevision": "1"}'"
B、数据展示为:
其四、正确的数据格式:
A、数据格式为:
'{"switch": "true","version": "RSTP","age": "20","delay": "15","count": "6","hops": "20","mstName": "name","matRevision": "1"}'
B、json.parse() 操作后的数据为:
{ switch: 'true', version: 'RSTP', age: '20', delay: '15', count: '6', hops: "20", mstName: "name", matRevision: "1"}
C、数据展示为:
其一、哪里有不对或不合适的地方,还请大佬们多多指点和交流!
其二、若有转发或引用本文章内容,请注明本博客地址 https://blog.csdn.net/weixin_43405300,创作不易,且行且珍惜!
其三、有兴趣的话,可以多多关注这个专栏(Vue(Vue2+Vue3)面试必备专栏):https://blog.csdn.net/weixin_43405300/category_11525646.html?spm=1001.2014.3001.5482