简体   繁体   中英

Not able to parse Array of string with single quotes around key value names

I am trying to parse an array to JSON.parse which have single quotes around the keys and values. But it is throwing following error.

Uncaught SyntaxError: Unexpected token ' in JSON at position 1

The array which I am passing is:

["{'name': 'Jhon'}"]

Somehow, this string is not throwing any error.

['{"name": "Jhon"}']

Any help will be appreciated. Thanks in advance.

JSON object names must be strings per the JSON spec. ECMA-404

The string specification to look at.

A string is a sequence of Unicode code points wrapped with quotation marks (U+0022).

The object specification to look at.

An object structure is represented as a pair of curly bracket tokens surrounding zero or more name/value pairs. A name is a string.

Which would make {'name': 'Jhon'} invalid since it violates both the string 'Jhon' and name 'name' specifications. Using double quotes is valid JSON { "name": "John" }

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