【问题标题】:parse/loop through this data and print name and merchant using javascript解析/循环通过此数据并使用 javascript 打印名称和商家
【发布时间】:2019-09-27 23:06:05
【问题描述】:
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) 但我没有定义。 我尝试使用 angular ng-repeat 但停留在访问动态数字键

【问题讨论】:

    标签: json object nested-loops


    【解决方案1】:

    您不能使用数字点表示法。为此使用括号。

    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);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-08
      • 1970-01-01
      相关资源
      最近更新 更多