我如何在这个响应中读取所有数据

How i can read all data in this response?

本文关键字:读取 数据 响应      更新时间:2023-09-26

我有这个JSON对象

{
  "0": {
    "id": "44",
    "date": "2016-06-24 10:53:08",
    "client_id": "44",
    "status": "waiting",
    "price": null,
    "paid": null,
    "client": false,
    "items": {
      "beirut": {
        "52": {
          "id": "52",
          "type": "Kerosene",
          "quantity": "50",
          "price": "20100",
          "address": "beirut"
        }
      }
    }
  },
  "1": {
    "id": "42",
    "date": "2016-06-24 10:43:35",
    "client_id": "44",
    "status": "waiting",
    "price": null,
    "paid": null,
    "client": false,
    "items": {
      "beirut": {
        "50": {
          "id": "50",
          "type": "Super 98",
          "quantity": "60",
          "price": "34900",
          "address": "beirut"
        }
      }
    }
  },
  "status": "ok"
}

我想读取 javascript中响应的所有数据。

jquery.ajax调用中作为datatype:jsonp返回。我能够访问数据,并显示所有的商店在html页面。

我怎么才能正确地阅读这个?

// Code goes here
var obj = {
  "0": {
    "id": "44",
    "date": "2016-06-24 10:53:08",
    "client_id": "44",
    "status": "waiting",
    "price": null,
    "paid": null,
    "client": false,
    "items": {
      "beirut": {
        "52": {
          "id": "52",
          "type": "Kerosene",
          "quantity": "50",
          "price": "20100",
          "address": "beirut"
        }
      }
    }
  },
  "1": {
    "id": "42",
    "date": "2016-06-24 10:43:35",
    "client_id": "44",
    "status": "waiting",
    "price": null,
    "paid": null,
    "client": false,
    "items": {
      "beirut": {
        "50": {
          "id": "50",
          "type": "Super 98",
          "quantity": "60",
          "price": "34900",
          "address": "beirut"
        }
      }
    }
  },
  "status": "ok"
}
Object.keys(obj).forEach(function(key){
  
 if (obj.hasOwnProperty(key)){
   console.log(key,obj[key]);
 }
})