Blogger Information
Blog 34
fans 0
comment 0
visits 19965
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
json常用API
OC的PHP大牛之路
Original
1335 people have browsed it

json常用API

json是通用的、轻量化的“数据交互格式”,用于前后端数据通信;
本质上json是一个格式化的字符串;它并不是js对象,但可以与js对象之间相互转换。

json的数据类型:
1.简单类型:number/string/boolean/null
2.数组:[…]
3.对象:{…}

1.js对象——>后端:JSON.stringify()

  1. // 1.js对象——>后端:JSON.stringify()
  2. // js对象
  3. const user={
  4. id:1,
  5. name:'朱老师',
  6. isMarried:true,
  7. };
  8. console.log(user);
  9. // js对象——>JSON
  10. let json=JSON.stringify(user);
  11. console.log(json);

2.后端——>js对象:JSON.parse()

  1. // 2.后端——>js对象:JSON.parse()
  2. // json字符串
  3. let str=`{
  4. "id":10,
  5. "name":"手机",
  6. "price":6999
  7. }`;
  8. console.log(str);
  9. // json——>js对象
  10. let item=JSON.parse(str);
  11. console.log(item);

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post