简体   繁体   中英

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

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

is this a valid json syntax? This was return from a Rest API call. I am trying to parse it using JSON.parse(...) method, but getting "Undefined Token U" error.

I am using it inside servicenow. Not sure if it is a service-now problem or json parsing error.

Make sure you're waiting for the response from the API call before trying to parse. Seems like you're attempting to parse before receiving the value, so your variable contains the value 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

If you're new to javascript, consider going through this answer on how to use the Fetch API

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM