当前位置:网站首页>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
边栏推荐
- Eyeshot Ultimate 2022 Crack By Xacker
- Use serialize in egg to read and write split tables
- Create an environment for new projects
- buuctf(re)
- Integrate CDN to create the ultimate service experience for customers!
- Basic knowledge of web pages (URL related)
- Eyeshot 2022 Released
- Wechat applet new version prompt update
- Why does the SQL statement hit the index faster than it does not?
- 渗透测试-目录遍历漏洞
猜你喜欢

How to download and use Xiaobai one click reload on the official website

Ranorex Studio 10.1 Crack

以太网是什么要怎么连接电脑

Small sample learning data set

My IC journey - the growth of senior chip design verification engineers - "Hu" said that IC engineers are perfect and advanced

魔法猪系统重装大师怎么使用

Route parameters to jump to the page and transfer parameters -- > hidden parameter list

great! Auto like, I use pyautogui!

DOM document object model (I)

What if the desktop computer is not connected to WiFi
随机推荐
In depth understanding of line height and vertical align
Svg code snippet of loading animation
TX Text Control 30.0 ActiveX
Notes on non replacement elements in the line (padding, margin, and border)
两小时带你进入软件测试行业风口(附全套软件测试学习路线)
H5 native player [learn video]
February 19 CTF exercise
XML (VIII)
DMA double buffer mode of stm32
How to make colleagues under the same LAN connect to their own MySQL database
How do the defi protocols perform under this round of stress test?
Filter & listener (XIV)
Database overview
JS function to realize simple calculator
TeeChart Pro ActiveX 2022.1
win11蓝牙无法连接怎么办?win11蓝牙无法连接的解决方法
Various pits encountered in the configuration of yolov3 on win10
Qdebug June 2022
Create an environment for new projects
JS handwriting depth clone array and object