我尝试解析uncaught Syntax Error
时收到JSON string
,我不知道为什么会失败。我测试了JSON字符串,它是有效的。
有人可以帮我解决这个问题。
我的代码段(在chrome中)如下:
var input = 'c:out escapeXml="false" value="[{"registeredCustomers":"81","node":"RAGS"},{"registeredCustomers":"39","node":"SBSA"}]" />';
var arr1 = [];
obj1 = JSON.parse(input);
答案 0 :(得分:0)
你必须做
input = input.replace("c:out escapeXml='false' value='", "")
然后JSON.parse(input);
答案 1 :(得分:0)
Json.parse
期待字符串。你可以试试这个:
var input = '[{\"registeredCustomers":"81","node":"RAGS"},
"registeredCustomers":"39","node":"SBSA"\}]';
var arr1 = [];
obj1 = JSON.parse(input);
console.log(obj1);
它将返回以下输出:
[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]
答案 2 :(得分:0)
由于输入中多次使用quote,您收到错误意外令牌c JSON.parse 。并且错误消息指向该行的开始。
value="[{"registeredCustomers":"81","node":"RAGS"},{"registeredCustomers":"39","node":"SBSA"}]"