当前位置:网站首页>JSON 与 JS 对象的区别
JSON 与 JS 对象的区别
2022-08-01 06:42:00 【元宇宙iwemeta】
JSON(JavaScript Object Notation),JS 对象表示法。
JSON 是 JS 对象的一种描述方式,使 JS 对象能够以文本的方式记录下来,所以 JSON 是字符串。所以,JSON 对象是一种错误的说法,我们在 JS 中自己写的 JSON 对象形式其实是 JSON 字符串解析为 JavaScript 中的数据结构形式。
为什么需要 JSON 对象?
JS 对象只有 JavaScript 自己认识,其他的语言都不认识。但 JSON 是一个特殊的字符串,这种格式的字符串能够被任意的语言所识别,可以转换为任意语言的对象形式,实现不同语言之间的数据交互。
JSON 与 JS 对象差别
JSON 与 JS 对象的格式一样,但是 JSON 的字符串中属性名必须加双引号。
JSON 分类
对象
let jsonObj = '{"name":"张三","age":18}'
1
数组
let jsonArr = '[{"name":"张三","age":18},18,true]'
1
JSON 与 JS 对象的转换
JavaScript 中的 JSON 类中含有 JSON 与 JS 对象相互转换的方法。
JSON 字符串转 JS 对象 ⇒ JSON.parse()
let jsonStr = '{"name":"张三","age":18}'
let jsObj = JSON.parse(jsonStr)
console.log(jsObj)// {name:'张三',age:18}
1
2
3
JS 对象转 JSON 字符串 ⇒ JSON.stringify()
let jsObj = {name:'张三',age:18}
let jsonStr = JSON.stringify(jsObj)// '{"name":"张三","age":18}'
边栏推荐
- matlab wind speed model wavelet filtering
- 从底层结构开始学习FPGA(6)----分布式RAM(DRAM,Distributed RAM)
- MVVM project development (commodity management system 1)
- leetcode43 string multiplication
- LeetCode 0149. Maximum number of points on a line
- 小白的0基础教程SQL: 什么是SQL 01
- LeetCode 0150. Reverse Polish Expression Evaluation
- How JS works
- Sound Signal Processing Fundamental Frequency Detection and Time-Frequency Analysis
- 特别数的和
猜你喜欢
随机推荐
LeetCode每日一题(309. Best Time to Buy and Sell Stock with Cooldown)
Zero-code website development tool: WordPress
AspNet.WebApi.Owin custom Token request parameters
点餐系统数据库设计--SQL Server
Datagrip error "The specified database userpassword combination is rejected..."Solutions
LeetCode 0149. 直线上最多的点数
weight distribution
测试工具(四)Jenkins环境搭建与使用
Solve the problem of page flicker caused by browser scroll bars
Explosive 30,000 words, the hardest core丨Mysql knowledge system, complete collection of commands [recommended collection]
matlab 风速模型 小波滤波
Srping bean in the life cycle
Flip letters using string container
NIO编程
安装SQL Server详细教程
响应式织梦模板园林花卉类网站
[Translation] Securing cloud-native communications: From ingress to service mesh and beyond
2022.7.27 Selected lectures on good topics
Bean的生命周期
LeetCode 0149. Maximum number of points on a line









![Explosive 30,000 words, the hardest core丨Mysql knowledge system, complete collection of commands [recommended collection]](/img/7f/08b323ffc5b5f8e3354bee6775b994.png)