当前位置:网站首页>JSON introduction
JSON introduction
2022-06-26 01:27:00 【Life needs depth】
JSON course
JSON: JavaScript Object Notation(JavaScript Object notation )
JSON Is the syntax for storing and exchanging text information , similar XML.
JSON Than XML smaller 、 faster , Easier to parse .
JSON example
{ "sites": [ { "name":" Novice tutorial " , "url":"www.runoob.com" }, { "name":"google" , "url":"www.google.com" }, { "name":" Microblogging " , "url":"www.weibo.com" } ] }
This sites The object is to contain 3 Site records ( object ) Array of .
What is? JSON ?
- JSON refer to JavaScript Object notation (JavaScript Object Notation)
- JSON It's a lightweight text data exchange format
- JSON Independent of language :JSON Use Javascript Syntax to describe data objects , however JSON Still independent of language and platform .JSON Parser and JSON The library supports many different programming languages . There's a lot of movement right now (PHP,JSP,.NET) Programming languages support JSON.
- JSON Be self descriptive , Easier to understand
JSON - Convert to JavaScript object
JSON Text format in syntax and create JavaScript The code of the object is the same .
Because of this similarity , No parser required ,JavaScript The program can use built-in eval() function , use JSON Data to generate native JavaScript object .
Online examples
Through our editor , You can edit it online JavaScript Code , Then click a button to see the results :
JSON example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> Novice tutorial (runoob.com)</title> </head> <body> <h2>JavaScript establish JSON object </h2> <p> Website name : <span id="jname"></span><br /> Web site address : <span id="jurl"></span><br /> Website slogan: <span id="jslogan"></span><br /> </p> <script>
var JSONObject= { "name":" Novice tutorial ", "url":"www.runoob.com", "slogan":" It's not just technology that you learn , Is the dream !" }; document.getElementById("jname").innerHTML=JSONObject.name document.getElementById("jurl").innerHTML=JSONObject.url document.getElementById("jslogan").innerHTML=JSONObject.slogan
</script> </body> </html>
Try it »
Click on " Try it " Button to view the online instance .
And XML Similarities
- JSON Is the plain text
- JSON have " self-description "( Human readable )
- JSON It has a hierarchy ( There is a value in the value )
- JSON It can be done by JavaScript To analyze
- JSON Data available AJAX transmitted
And XML The difference
- No end tag
- shorter
- Faster reading and writing
- Be able to use built-in JavaScript eval() Method
- Using arrays
- Reserved words are not used
Why use JSON?
about AJAX For applications ,JSON Than XML Faster and easier to use :
Use XML
- Read XML file
- Use XML DOM To loop through the document
- Read the value and store it in the variable
Use JSON
- Read JSON character string
- use eval() Handle JSON character string
JSON vs XML
JSON and XML All for receiving web Data on the server .
JSON and XML There are differences in writing , As shown below :
JSON example
{ "sites": [ { "name":" Novice tutorial " , "url":"www.runoob.com" }, { "name":"google" , "url":"www.google.com" }, { "name":" Microblogging " , "url":"www.weibo.com" } ] }
XML example
<sites> <site> <name> Novice tutorial </name> <url>www.runoob.com</url> </site> <site> <name>google</name> <url>www.google.com</url> </site> <site> <name> Microblogging </name> <url>www.weibo.com</url> </site> </sites>
JSON And XML The similarities :
- JSON and XML The data are all " Self description " , Are easy to understand .
- JSON and XML The data has a hierarchical structure
- JSON and XML Data can be used by most programming languages
JSON And XML The difference :
- JSON There is no need to end the tag
- JSON Shorter
- JSON Faster reading and writing
- JSON You can use arrays
The biggest difference is :XML Need to use XML Parsers to parse ,JSON You can use standard JavaScript Function to parse .
- JSON.parse(): Will a JSON String conversion to JavaScript object .
- JSON.stringify(): At will JavaScript Value to JSON character string .
Why? JSON Than XML Better ?
XML Than JSON It's harder to parse .
JSON You can use the existing JavaScript Object parsing .
in the light of AJAX application ,JSON Than XML Data loads faster , And it's simpler :
Use XML
- obtain XML file
- Use XML DOM Iterative loop document
- Then the data is parsed and copied to the variable
Use JSON
- obtain JSON character string
- JSON.Parse analysis JSON character string
Related articles
- JavaScript JSON: JavaScript JSON | Novice tutorial
- XML DOM course : XML DOM course | Novice tutorial
边栏推荐
- QT cmake pure C code calls the system console to input scanf and Chinese output garbled code
- Embedded C first learning notes
- Classic interview questions: mouse drug test and Hamming code
- A sharp tool for information collection, Google hacker syntax
- Laravel basic course routing and MVC - controller
- 生信周刊第34期
- 返回值为Object型方法调用equals()
- Mpu6050 reads the ID incorrectly and 0xd1 occurs (the correct ID should be 0x68 or 0x69). Solution.
- How to effectively promote products
- Musk vs. jobs, who is the greatest entrepreneur in the 21st century
猜你喜欢

Multiple interface calls, using promise all、Promise. Race and promise any

生信周刊第33期

STM32GPIO

Idea configuration

FIFO code implemented in C language

Technical introduction - detailed explanation of chip manufacturing process

数字电路——加法器

Redis strings command

生信周刊第34期

Duck feeding data instant collection solution resources
随机推荐
[flower carving experience] 11 start esp32c3
Longitude and latitude multipoint acquisition center point has been solved
Redis strings command
同花顺上登录股票账户是安全的吗?同花顺上是如何开股票账户的
Technical introduction - detailed explanation of chip manufacturing process
Template engine - FreeMarker first experience
接口的幂等性——详细谈谈接口的幂等即解决方案
Region of Halcon: generation of multiple regions (4)
Black box test - decision table method of test cases
集合集合!!快来复习--mysql增删改查,内、左右连接 复习笔记
Dgus new upgrade: fully support digital video playback function
在FreeBSD中安装MySQL数据库
FreeRTOS+STM32L+ESP8266+MQTT协议传输温湿度数据到腾讯云物联网平台
Etcd database source code analysis -- inter cluster network layer server interface
Web信息收集,互联网上的裸奔者
Is it safe to open a securities account online
Laravel basic course routing and MVC - controller
开窍之问答
Inheritance -- holy grail mode
DGUS新升级:全面支持数字视频播放功能