JSON.parse solve Unexpected token 'in JSON at position 1 error

 One ❀ lead

We know JSON.parse able JSON string into a JS object, but may appear in some conversions in Unexpected token 'in JSON at position 1 error, because the converted value does not meet JSON format caused.

JSON official clearly defined, JSON data key and value must use double quotes "" package , or in the conversion process results in an error.

A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested.

A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.

 Example II ❀

// array of 
the let A = '[ "A", "B", "C"]'; //  
the let B = "[ 'A', 'B', 'C']"; // X- 

// Object 
let a1 = '{ "name" : " hear the wind is the wind", "Age": "26 is"}'; //  
the let B1 = "{ 'name': 'hear the wind is the wind', 'age': ' 26 is'} "; // X- 

the console.log (the JSON.parse (A)) // the Array 
the console.log (the JSON.parse (A1)) // Object 
the console.log (the JSON.parse (B)) // given 
the console.log (the JSON.parse (B1)) // given

If you JSON.stringify () and JSON.parse () differ doubts, and what their role in the actual development, Welcome to the blogger  json.stringify () Magical, json.stringify () and json.parse () the difference between this article.

I hope for your help, then this article is over.

Guess you like

Origin www.cnblogs.com/echolun/p/11720161.html