ajax请求返回数据,多层嵌套,前端怎么获取

1.后台返回数据,不知道怎么获取到price里面的值,试了好多,一直显示不出来。
2.返回数据如下: {
"ret": 0,
"ret_msg": "",
"list": [

          {
          "target_id": 0,
        "target_name": "",
        "price": [
            {
                "currency": 0,
                "amount": 1,
                "valid_duration": {
                    "start_time": 0,
                    "end_time": 0
                },
                "vasset_info": {
                    "vasset_name": "",
                    "vasset_price": 5,
                    "vasset_amount": 3,
                    "vasset_desc": "",
                            "usable_duration": {
                            "value": 12,
                            "unit": 1
                              }
                }
            }
        ],
        "order_type": 1,
        "sub_type": 1,
        "target_type": 0,
        "usable_duration": {
           "value":0,
           "unit":0
        },
        "available_duration": {
            "start_time": 0,
            "end_time": 0
        },
        "desc": ""
    }
],

"total": 0
}

阅读 4.8k
4 个回答
新手上路,请多包涵

list.price.currency

data.list[0].price[0]

如果数据是json格式的,请记得JSON.parse()这个方法的使用

没看错应该是下面这样?
    var json={
        "ret": 0,
        "ret_msg": "",
        "list": [{
            "target_id": 0,
            "target_name": "",
            "price": [{
                "currency": 0,
                "amount": 1,
                "valid_duration": {
                    "start_time": 0,
                    "end_time": 0
                }
            }],
        }],
    }
console.log(json.list[0].price[0].currency);
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题