当前位置:网站首页>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
边栏推荐
- 让每一位开发者皆可使用机器学习技术
- Mathematical statistics and machine learning
- PHP read file (read JSON file, convert to array)
- AttributeError: ‘str‘ object has no attribute ‘decode‘
- Common websites for Postgraduates in data mining
- Redis Key-Value数据库【初级】
- 使用sha256文件验证下载的文件
- 神机百炼3.54-染色法判定二分图
- Talking about MySQL database
- [leetcode] day92 container with the most water
猜你喜欢
51 single chip microcomputer - ADC explanation (a/d conversion, d/a conversion)
The official zero foundation introduction jetpack compose Chinese course is coming!
经典文献阅读之--SuMa++
如何使用MITMPROXy
[whether PHP has soap extensions installed] a common problem for PHP to implement soap proxy: how to handle class' SoapClient 'not found in PHP
mysql的约束总结
谷歌出海创业加速器报名倒计时 3 天,创业人闯关指南提前收藏!
Jetpack Compose 与 Material You 常见问题解答
Little bear sect manual query and ADC in-depth study
神机百炼3.54-染色法判定二分图
随机推荐
Zabbix Server trapper 命令注入漏洞 (CVE-2017-2824)
Stc8h8k series assembly and C51 actual combat - serial port sending menu interface to select different functions
脑与认知神经科学Matlab Psytoolbox认知科学实验设计——实验设计四
CNN可视化技术 -- CAM & Grad-CAM详解及pytorch简洁实现
How vite is compatible with lower version browsers
Picture clipping plug-in cropper js
How to use mitmproxy
JWT工具类
php父类(parent)
Deep learning classification network -- alexnet
TypeScript的泛型和泛型约束
社区说|Kotlin Flow 的原理与设计哲学
Little bear sect manual query and ADC in-depth study
500. 键盘行
1035 Password
No subject alternative DNS name matching updates. jenkins. IO found, the reason for the error and how to solve it
Comment utiliser mitmproxy
Happy Lantern Festival | Qiming cloud invites you to guess lantern riddles
php获取cpu使用率、硬盘使用、内存使用
Servlet web XML configuration details (3.0)