[英]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.我正在尝试将数组解析为 JSON.parse ,其中键和值周围有单引号。 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. JSON object 名称必须是符合 JSON 规范的字符串。 ECMA-404
ECMA-404
The string specification to look at.要查看的字符串规范。
A string is a sequence of Unicode code points wrapped with quotation marks (U+0022).
字符串是用引号 (U+0022) 包裹的 Unicode 代码点序列。
The object specification to look at.要查看的 object 规范。
An object structure is represented as a pair of curly bracket tokens surrounding zero or more name/value pairs.
object 结构表示为一对围绕零个或多个名称/值对的花括号标记。 A name is a string.
名称是一个字符串。
Which would make {'name': 'Jhon'}
invalid since it violates both the string 'Jhon'
and name 'name'
specifications.这会使
{'name': 'Jhon'}
无效,因为它违反了字符串'Jhon'
和名称'name'
规范。 Using double quotes is valid JSON { "name": "John" }
使用双引号是有效的 JSON
{ "name": "John" }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.