当前位置:网站首页>Jason learning
Jason learning
2022-06-25 05:08:00 【Lijianyi】
Json:JavaScript Object Notation(JavaScript Object representation of )
Json It's a syntax for storing and exchanging text information , Its representation is similar to JavaScript Of the key/value Representation , Or object representation
var JsonString = {
"name": "herry",
"age": 12,
"slogan": "dream-mack"
};
console.log(JsonString.name);
var JsonString1 = [
{"name": "herry", "age": 20, "slogen": "dream-top1"},
{"name1": "monica", "age": 24, "slogen": "dream-top2"},
{"name": "butter", "age": 28, "slogen": "dream-top3"}
];
console.log(JsonString1[0].name);
for(item in JsonString1[1]){
console.log(item); //name1, age, slogen
}
for(val in JsonString1[1]){
console.log(JsonString1[1][val]); //monica, 24, dream-top2
}
var JsonString2 = {
"name": "herry",
"age": 20,
"solgan": {
"solgan1": "dream-left1",
"solgan2": "dream-left2",
"solgan3": "dream-left3"
}
}
console.log(JsonString2.solgan.solgan1); //dream-left1
var JsonString3 = {
"name": "herry",
"age": [12, 13, 15]
}
console.log(JsonString3.age[2]); //15
Json The suffix of the file is .json file ,MIME Type bit application/json. Use directly when calling json In the previous method name, just click the specific attribute , Or use square bracket notation to get .
It can also be used directly for in perhaps forEach And so on
Delete the value and use it directly delete Delete specific key The value will do
Json Grammatical rules :
Data usage key:value Method representation of , Data is separated by commas , Braces hold objects , The brackets hold the array
Json Arrays in can be used with object methods , Achieve the purpose of nesting . It can also be used directly json Get the index in the array and modify its elements
var text = '{ "name":"Runoob", "initDate":"2013-12-14", "site":"www.runoob.com"}';
var obj = JSON.parse(text);
obj.initDate = new Date(obj.initDate);
console.log(obj.initDate); // Sat Dec 14 2013 08:00:00 GMT+0800 ( China standard time )
var text1 = '{ "name":"Runoob", "alexa":"function () {return 10000;}", "site":"www.runoob.com"}';
var obj = JSON.parse(text1);
obj.alexa = eval("(" + obj.alexa + ")");
console.log(obj.alexa()); // 10000
json You can save numbers in (int / float), character string ,Boolean, Array , object ,null
Note here json Can't save Date object , Cannot save function , Both of these need to be converted into strings first , Turn back
stay json In which ”name”: “herry”, stay js Manifested as name: “herry”
var stringJson = '{"name": "herry", "age": 20, "solgen": "dream-top"}';
var jsonString = JSON.parse(stringJson);
console.log(jsonString.name); //herry
var jsonString1 = {
"name": "herry",
"age": 20,
"solgen": "dreame-top"
};
var stringJson1 = JSON.stringify(jsonString1);
console.log(stringJson1); // {"name":"herry","age":20,"solgen":"dreame-top"}
Use json Medium parse( ) Method to convert the data json Format file to JavaScript object
Use json Medium stringify( ) Method JavaScript Object to string , You can also convert arrays to strings
Mainstream browsers support stringify( ) Method :firefox3.5、ie8、chrome、opera10、safari4
Try not to use eval( ) Method , Prone to security problems , Use as much as possible parse( ) Method
边栏推荐
- PHP uses JWT
- Apache+php uploading large files
- 渗透测试-目录遍历漏洞
- On Transform
- Laravel Aurora push
- 基于Cortex-M3、M4的精准延时(系统定时器SysTick延时,可用于STM32、ADuCM4050等)
- Heavy broadcast | phase shift method + mathematical principle derivation of multi frequency heterodyne + implementation
- 小白一键重装官网下载使用方法
- Kotlin compose perfect todo project surface rendering background and shadow
- Attack and defense world web baby Web
猜你喜欢
小白一键重装官网下载使用方法
TeeChart Pro ActiveX 2022.1
Kotlin compose listens to the soft keyboard and clicks enter to submit the event
MySQL concept and operation (III)
《QDebug 2022年6月》
How to use the Magic pig system reinstallation master
[image fusion] image fusion based on MATLAB directional discrete cosine transform and principal component analysis [including Matlab source code 1907]
ThinkPHP 5 log management
buuctf(re)
Deeply understand the characteristics of standard flow and off standard elements
随机推荐
For in JS Of and for in
Could not find “store“ in the context of “Connect(homePage)
In Net 6 using dotnet format formatting code
Opensea PHP development kit
渗透测试-提权专题
融合CDN,为客户打造极致服务体验!
File upload vulnerability (III)
电脑的dwg文件怎么打开
dotnet-exec 0.4.0 released
Mysql interactive_ Timeout and wait_ Timeout differences
H5 native player [learn video]
How PHP gets the user's City
Everything is an object
win11蓝牙无法连接怎么办?win11蓝牙无法连接的解决方法
Detailed summary of position positioning
Understand JS high-order function and write a high-order function
电子协会 C语言 1级 28 、字符菱形
Svg code snippet of loading animation
XML (VIII)
Creation and use of MySQL index