Home>Article>Web Front-end> JSON you don’t know much about
Preface
Although the probability of being asked about this knowledge point in the interview is very low, it may still be asked.
The reason why JSON is popular
Has a syntax similar to js
You can JSON data structure is parsed into js objects
Compared with XML data structure, extracting data is simpler
JSON syntax
Simple value
String=>“123”
Value= >123
Boolean=>true
Object
{"name": "helin","age": 12}Array
[ {"name": " iskeeping","age": 12} ] Note: The JSON key must use double quotes, and if the value is a string, it must also use double quotes. JSON parsing method 1. Use evaleval("({\"name\":\"iskeeping\"})")2. Use Functionnew
Function("", "return ({\"name\":\"iskeeping\"})")()3. Use JSON.parse
JSON.parse("{\"name\":\"iskeeping\"}")
JSON serialization
let formateJson = JSON.stringify({ name: "iskeeping", age: 12 }, function (key, value) { switch (key) { case "name": return "iskeepingxx"; default: return value; } }, 8) cosnole.log(formateJson)Output formatJson as shown below: ##JSON Native support
Native JSON objects are supported by the following browsers.
IE8, Firefox3.5, Safari 4, Opera 10.5 and chrome
Thank you for reading!
If you need to communicate on WeChat, you can leave a message!
Recommended tutorial: "
JS TutorialThe above is the detailed content of JSON you don’t know much about. For more information, please follow other related articles on the PHP Chinese website!