Home >Web Front-end >JS Tutorial >A preliminary understanding of JSON
JSON plays an important role in JavaScript, and this article will explain it in detail.
<html> <body> <h2>在 JavaScript 中创建 JSON 对象</h2> <p> Name: <span id="jname"></span><br /> Age: <span id="jage"></span><br /> Address: <span id="jstreet"></span><br /> Phone: <span id="jphone"></span><br /> </p> <script type="text/javascript">var JSONObject= { "name":"Bill Gates", "street":"Fifth Avenue New York 666", "age":56, "phone":"555 1234567"};document.getElementById("jname").innerHTML=JSONObject.namedocument.getElementById("jage").innerHTML=JSONObject.agedocument.getElementById("jstreet").innerHTML=JSONObject.streetdocument.getElementById("jphone").innerHTML=JSONObject.phone</script> </body> </html>
Like XML
JSON is plain text
JSON is "self-descriptive" (human readable)
JSON has a hierarchical structure (in values Value exists)
JSON can be parsed through JavaScript
JSON data can be transmitted using AJAX
Differences compared to XML
No end tag
Shorter
Read and write faster
Can use the built-in JavaScript eval() method for parsing
Use arrays
Not usedReserved words
Why use JSON?
JSON is faster and easier to use than XML for AJAX applications:
Using XML
Reading XML documents
Using XML DOM for looping Traverse the document
Read values and store in variables
Use JSON
Read JSON String
Use eval( ) Processing JSON string
This article provides a relevant explanation of json. For more learning materials, please pay attention to the php Chinese website.
Related recommendations:
Related knowledge about PHP filters
About the operation of PHP exception handling
About PHP file opening/reading/reading related knowledge
The above is the detailed content of A preliminary understanding of JSON. For more information, please follow other related articles on the PHP Chinese website!