我尝试使用JSON.parse解析以下JSON字符串(从服务器生成并返回):
var x = d3.scaleTime().range([0, width]);
var x2 = d3.scaleTime().range([0, width]);
var xAxis = d3.axisBottom(x).ticks(d3.timeDay).tickFormat(d3.timeFormat("%x"));
var xAxis2 = d3.axisBottom(x2).ticks(10).tickFormat(d3.timeFormat("%x"));
但是我收到了这个错误:
[{"id":1,"username":"klebermo","password":"$2a$04$YYqryKrcmUQfwmbsnhA1Te0FghiYsirxVq.Wf.kChjpEm/uuky.fu","firstName":"Kleber","lastName":"Mota","email":"klebermo@gmail.com","credenciais":[{"id":1,"nome":"user","autorizacoes":[{"id":1,"nome":"user","authority":"user"}]},{"id":2,"nome":"admin","autorizacoes":[{"id":2,"nome":"admin","authority":"admin"}]}],"enabled":true,"credentialsNonExpired":true,"accountNonLocked":true,"accountNonExpired":true,"authorities":[{"id":1,"nome":"user","authority":"user"},{"id":2,"nome":"admin","authority":"admin"}]}]
我的javascript代码,其中解析变形:
Uncaught SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at Object.success ((index):186)
at i (jquery-3.2.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-3.2.1.min.js:2)
at A (jquery-3.2.1.min.js:4)
at XMLHttpRequest.<anonymous> (jquery-3.2.1.min.js:4)
如果我尝试在多个json验证站点中验证JSON字符串,则不会显示错误。 JSON列在浏览器开发人员工具的“网络”选项卡中,并且也显示正确。
任何人都可以暗示这里可能出现的问题?
答案 0 :(得分:3)
它已经是一个对象。无需解析它。
位置1的[object Object]
是{{1}}的第二个符号。