json - 解析/循环通过此数据并使用 javascript 打印名称和商家
问题描述
aqw= {
"res": {
"statiscs":{
"traffic": {
"0": {
"name": "S0",
"bytes": 87
},
"1": {
"name": "S1",
"bytes": 837
},
"3": {
"state": [
{
"merchant": "seno",
"vendor": "miami"
}
],
"name": "S1",
"bytes": 837
}
}
}
}
}
console.log('...', aqw.res.statiscs.traffic.0.name);
我尝试使用 console.log('...', aqw.res.statiscs.traffic.0.name) 但我没有定义。我尝试使用角度 ng-repeat 但停留在访问动态数字键
解决方案
您不能使用数字点表示法。为此使用括号。
aqw= {
"res": {
"statiscs":{
"traffic": {
"0": {
"name": "S0",
"bytes": 87
},
"1": {
"name": "S1",
"bytes": 837
},
"3": {
"state": [
{
"merchant": "seno",
"vendor": "miami"
}
],
"name": "S1",
"bytes": 837
}
}
}
}
}
console.log('...', aqw.res.statiscs.traffic["0"].name);
推荐阅读
- javascript - 如何在 jquery 中显示延迟的选项卡?
- javascript - 忽略[url][img]内的所有内容的正则表达式
- flutter - Dart http.client 未接收到 SSE“数据”字段
- java - java.net.ConnectException:连接超时:JAVA 中的连接错误和相同的逻辑在 .NET 中工作正常
- excel - 如果某些单元格说“是”,则 VBA 添加行
- powerbi - 加密数据上的 Power BI
- excel - 如果日期在两个单元格的日期范围内,则返回是或否值的公式
- javascript - 使用带有变换反馈的两个缓冲区
- c# - 错误 NETSDK1004:找不到资产文件“project.assets.json”
- javascript - 根据使用 HTML 和 Javascript 的 2 个下拉列表选择的条件显示 DIV