I am trying to parse a String response from an API to JSON in ReactJS.
My string response looks like this:
[{"fromArea":"chocolate","toArea":"chocolate","distance":"100"},{"fromArea":"strawberry","toArea":"strawberry","distance":"200"},{"fromArea":"vanilla","toArea":"vanilla","distance":"300"}]
So far, I have tried:
JSON.parse(element.permission))
JSON.parse("\'"+element.permission+"\'")
I am getting error as:
AppliedPermissions.js:18 Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1
Referred from:
Convert string array to array in javascript
Any help would be constructive.
parse()returning if it isnt throwing errors? How are you retrieving the response? Is it maybe already parsed, as libraries likejQuerywill do? Provide a minimal reproducible example that shows the problemAppliedPermissions.js:18 Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1JSON.parsedoesn't work for you, you should supply a minimal reproducible example because your code is correct.Unexpected token o in JSON at position 1you most likely already have an object. Why do you think you need to parse it?