当前位置:网站首页>JSON object
JSON object
2022-07-25 22:31:00 【Like the rising sun】
1. Preface
I have learned today JavaScript JSON, Want to learn well JavaScript JSON, You need to know first JSON What is it? ,JSON(JavaScript Object Notation) Is a kind of formatted text ,JavaScript Medium JSON object Used to process this kind of text .
2.JSON object
JSON The object is enclosed in curly braces {} Surround .
JSON Object with key / Value pair writing .
The key must be a string , Value must be valid JSON data type ( character string 、 Numbers 、 object 、 Array 、 Boor or null).
Keys and values are separated by colons .
Each key / Value pairs are separated by commas .
1. Access object value
You can use point numbers (.) To access object values :
var myJSON = {
"name":"xiaot", "sex":"male", "age":32 }
var jsonName = myJSON.name;
console.log(jsonName);
Words can be passed through square brackets ([]) To access object values :
var myJSON = {
"name":"xiaot", "sex":"male", "age":32 }
var jsonName = myJSON["name"];
console.log(jsonName);
2. Traversing objects
Sure By using for-in Traverse object properties :
<!DOCTYPE html>
<html>
<body>
<p> Traverse JSON All properties in the object .</p>
<p id="demo"></p>
<script> var myJSON = {
"name": "xiaot", "sex": "male", "age": 32 } var x; for (x in myJSON) {
document.getElementById("demo").innerHTML += x + "</br>"; } </script>
</body>
</html>
The running code is as follows :

3. nesting JSON object
nesting JSON Object refers to a JSON The value in the object can be another JSON object .
myJSON = {
"name": "xiaot",
"age": 88,
"cars": {
"car1": "lamborghini",
"car2": "Mercedes Benz",
"car3": "Bugatti Veyron"
}
}
Nested JSON object :
x = myJSON.cars.car2;
// perhaps
x = myJSON.cars["car2"];
console.log(x);
You can make it clear from the console 
3. Summary
about AJAX For applications ,JSON Than XML Faster and easier to use , So mastering these knowledge points is beneficial without harm !
边栏推荐
- torchvision
- torchvision
- Wechat official account application development (I)
- Box model (2)
- QML module not found
- mysql: error while loading shared libraries: libncurses.so. 5: cannot open shared object file: No suc
- It's over. I went to work for three months and became bald
- Formal parameters, arguments and return values in functions
- 【集训DAY11】Nescafe【贪心】
- Xiaobai programmer's fifth day
猜你喜欢

【集训DAY15】简单计算【树状数组】【数学】

ThreadLocal 总结(未完待续)

Win10 set up a flutter environment to step on the pit diary

数据平台下的数据治理

Wechat card issuing applet source code - automatic card issuing applet source code - with flow main function

Binder principle

Use of hyperlinks

软件测试 pytest pytest的命名规则 用例的前后置 conftest.py 定制allure报告 @pytest.mark.parametrize()装饰器作数据驱动
![[C syntax] void*](/img/34/b29b7bbf8eae9f1730352cac1301a4.png)
[C syntax] void*

Get together for ten years, tell your story, millions of gifts are waiting for you
随机推荐
Pyspark data analysis basis: pyspark.sql.sparksession class method explanation and operation + code display
Data type conversion
VIM usage record
IPv4地址已经完全耗尽,互联网还能正常运转,NAT是最大功臣!
scrapy无缝对接布隆过滤器
[training Day12] min ratio [DFS] [minimum spanning tree]
Select structure if branch structure
Floating effect and characteristics
Data quality: the core of data governance
What is class loading? Class loading process?
If it is modified according to the name of the framework module
xss-收集常用的代码
【集训DAY15】简单计算【树状数组】【数学】
Ffmpeg plays audio and video, time_ Base solves the problem of audio synchronization and SDL renders the picture
数据质量:数据治理的核心
[C syntax] void*
【集训DAY12】Bee GO!【动态规划】【数学】
Method of converting MAPGIS format to ArcGIS
Simulated Xiaomi mall head home page
xxl-job中 关于所有日志系统的源码的解读(一行一行源码解读)