当前位置:网站首页>Detailed steps of JS foreground parsing of complex JSON data "case: I"
Detailed steps of JS foreground parsing of complex JSON data "case: I"
2022-07-02 06:05:00 【A big moon】
One 、 Go straight to the code !
This is from the backstage to the front desk json Format string :
var p = '{"spec": [{"a": "XS"}, {"b": "S"}, {"2": "M"}, {"3": "L"}, {"4": "XL"}, {"5": "XXL"}]}'
1. The first step is to turn first First the json String to JavaScript object :
var a =JSON.parse(p) ;
Direct output , Take a look at the data format
a

Verify the data format
typeof(a)

typeof(p)

Verification is OK !
2. Loop data
As shown in the figure below , Analysis data format :
JavaScript object The attribute name :spec The corresponding value is length 6 Array of ,
6 Elements They have their own key And corresponding value
3. Circular array , Get data !
Get the array :
a.spec


a.spec.forEach(function(obj,index){
console.log(Object.keys(obj)[0]);
console.log(Object.values(obj)[0]);
})
adopt Object.keys(obj)[0] Method , obtain Array Element object key value , Cycle and print :
adopt Object.values(obj)[0] Method , obtain Array Element object value value , Cycle and print :
Okay , That's it , Have a question ,
Welcome to exchange :QQ 1531613221 QQ Group 201455739
边栏推荐
猜你喜欢

Zabbix Server trapper 命令注入漏洞 (CVE-2017-2824)

Compte à rebours de 3 jours pour l'inscription à l'accélérateur de démarrage Google Sea, Guide de démarrage collecté à l'avance!
![[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法](/img/25/73f11ab2711ed2cc9f20bc7f9116b6.png)
[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法

Ti millimeter wave radar learning (I)

Keepalived installation, use and quick start
![[whether PHP has soap extensions installed] a common problem for PHP to implement soap proxy: how to handle class' SoapClient 'not found in PHP](/img/25/73f11ab2711ed2cc9f20bc7f9116b6.png)
[whether PHP has soap extensions installed] a common problem for PHP to implement soap proxy: how to handle class' SoapClient 'not found in PHP

vite如何兼容低版本浏览器

如何使用MITMPROXy

深度学习分类网络 -- AlexNet

keepalived安装使用与快速入门
随机推荐
php数组转化为xml
Spark overview
[C language] screening method for prime numbers
Vite打包后的dist不能直接在浏览器打开吗
Use some common functions of hbuilderx
Style modification of Mui bottom navigation
495. Timo attack
Go 学习笔记整合
神机百炼3.52-Prim
CNN可视化技术 -- CAM & Grad-CAM详解及pytorch简洁实现
No subject alternative DNS name matching updates. jenkins. IO found, the reason for the error and how to solve it
STC8H8K系列匯編和C51實戰——數碼管顯示ADC、按鍵串口回複按鍵號與ADC數值
Some descriptions of Mipi protocol of LCD
mysql的约束总结
STC8H8K系列汇编和C51实战——按键允许按键计数(利用下降沿中断控制)
cookie插件和localForage离线储存插件
从设计交付到开发,轻松畅快高效率!
token过期自动续费方案和实现
官方零基础入门 Jetpack Compose 的中文课程来啦!
ROS2----LifecycleNode生命周期节点总结