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