简体   繁体   English

未捕获的语法错误:意外的令牌 c JSON.parse

[英]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.

相关问题 未捕获到的SyntaxError:意外令牌[与JSON.parse - Uncaught SyntaxError: Unexpected token [ with JSON.parse "未捕获的 SyntaxError:带有 JSON.parse 的意外标记" - Uncaught SyntaxError: Unexpected token with JSON.parse 未捕获到的SyntaxError:JSON中的意外令牌u在JSON.parse的位置0 - Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse 未捕获的SyntaxError:JSON.parse中位置0的JSON中的意外标记a( <anonymous> ) - Uncaught SyntaxError: Unexpected token a in JSON at position 0 at JSON.parse (<anonymous>) 未捕获到的SyntaxError:JSON中的意外令牌&lt;在JSON.parse位置0处( <anonymous> ) - Uncaught SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) Uncaught SyntaxError: Unexpected token & in JSON at position 1 at JSON.parse (<anonymous> )</anonymous> - Uncaught SyntaxError: Unexpected token & in JSON at position 1 at JSON.parse (<anonymous>) Javascript JSON.parse:Uncaught SyntaxError:意外的令牌N. - Javascript JSON.parse: Uncaught SyntaxError: Unexpected token N Uncaught SyntaxError:意外的令牌o- JSON.Parse - Uncaught SyntaxError: Unexpected token o- JSON.Parse JSON.parse()和$ .parseJSON()中的“未捕获的SyntaxError:意外的令牌?” - “Uncaught SyntaxError: Unexpected token ?” in both JSON.parse() and $.parseJSON() JSON.parse得到“Uncaught SyntaxError:Unexpected token h” - JSON.parse get “Uncaught SyntaxError: Unexpected token h”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM