[英]Uncaught SyntaxError: Unexpected token c JSON.parse
I'm getting an uncaught Syntax Error
when I try to parse a JSON string
, I'm not sure why it is failing.当我尝试解析一个JSON string
,我遇到了一个uncaught Syntax Error
,我不确定它为什么会失败。 I've tested the JSON string and it is valid.我已经测试了 JSON 字符串,它是有效的。
Can someone please help me with this issue.有人可以帮我解决这个问题。
My code snippet (in chrome) is as follows:我的代码片段(在 chrome 中)如下:
var input = 'c:out escapeXml="false" value="[{"registeredCustomers":"81","node":"RAGS"},{"registeredCustomers":"39","node":"SBSA"}]" />';
var arr1 = [];
obj1 = JSON.parse(input);
You have to do你必须要做
input = input.replace("c:out escapeXml='false' value='", "")
and then JSON.parse(input);
然后JSON.parse(input);
Json.parse
expect the string. Json.parse
期望字符串。 You can try this:你可以试试这个:
var input = '[{\"registeredCustomers":"81","node":"RAGS"},
"registeredCustomers":"39","node":"SBSA"\}]';
var arr1 = [];
obj1 = JSON.parse(input);
console.log(obj1);
it will return the following output:它将返回以下输出:
[Object, Object, $family: function, $constructor: function, each: function, clone: function, clean: function…]
0: Object
node: "RAGS"
registeredCustomers: "81"
__proto__: Object
1: Object
node: "SBSA"
registeredCustomers: "39"
__proto__: Object
length: 2
__proto__: Array[0]
You are getting that error Unexpected token c JSON.parse due to the multiple time usage of quote in the input.由于在输入中多次使用引用,您收到错误Unexpected token c JSON.parse 。 And the error message is pointing to starting of the line.并且错误消息指向行的开头。
value="[{"registeredCustomers":"81","node":"RAGS"},{"registeredCustomers":"39","node":"SBSA"}]"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.