简体   繁体   English

在 REST 响应上使用 JSON.parse(...) 时出现 Unexpected Token U 错误

[英]getting Unexpected Token U error when using JSON.parse(…) on REST Response

{"xx": {"zz": { "yy": "YY", "aa": "AA" }}} {“xx”:{“zz”:{“yy”:“YY”,“aa”:“AA”}}}

is this a valid json syntax?这是有效的 json 语法吗? This was return from a Rest API call.这是从 Rest API 调用返回的。 I am trying to parse it using JSON.parse(...) method, but getting "Undefined Token U" error.我正在尝试使用 JSON.parse(...) 方法对其进行解析,但出现“未定义的令牌 U”错误。

I am using it inside servicenow.我在 servicenow 中使用它。 Not sure if it is a service-now problem or json parsing error.不知道是 service-now 问题还是 json 解析错误。

Make sure you're waiting for the response from the API call before trying to parse.在尝试解析之前,请确保您正在等待来自 API 调用的响应。 Seems like you're attempting to parse before receiving the value, so your variable contains the value undefined .似乎您在接收值之前尝试解析,因此您的变量包含值undefined (Could also be caused by a typo in the variable name) (也可能是由变量名中的拼写错误引起的)

When you try to parse that you'll get an error Unexpected token u in JSON at position 0当您尝试解析时,您将收到错误Unexpected token u in JSON at position 0

If you're new to javascript, consider going through this answer on how to use the Fetch API如果您是 javascript 的新手,请考虑通过此答案了解如何使用Fetch API

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用JSON.parse时,&#39;未捕获的SyntaxError:意外的标记u&#39; - 'Uncaught SyntaxError: Unexpected token u' when using JSON.parse 解析错误JSON.parse(意外令牌u) - parsing error JSON.parse(unexpected token u) 意外的令牌:你的JSON.parse()问题 - Unexpected token: u JSON.parse() issue Uncaught SyntaxError: JSON.parse (<anonymous> ) 在 Response.Body.json</anonymous> - Uncaught SyntaxError: Unexpected token U in JSON at position 0 at JSON.parse (<anonymous>) at Response.Body.json 从asyncStorage获取时的JSON.parse(object)引发错误:位置1的JSON中的意外令牌o - JSON.parse(object) when getting from asyncStorage throws error: Unexpected token o in JSON at position 1 在JSON名称和JSON.parse中使用冒号时出现“意外令牌” - 'Unexpected token' when using colon in json name and JSON.parse 我正在使用Ionic并收到错误消息:SyntaxError:JSON中的意外标记&lt;在JSON.parse位置0处( <anonymous> ) - I am using ionic and getting an error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) 使用JSON.parse时,出现“ SyntaxError:JSON中位置1的意外令牌” - I am getting “SyntaxError: Unexpected token ' in JSON at position 1” when using JSON.parse 未捕获到的SyntaxError:JSON中的意外令牌u在JSON.parse的位置0 - Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse JSON.parse 位置 0 处的 JSON 中的意外标记 u - Unexpected token u in JSON at position 0 at JSON.parse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM