我如何阅读此回复中的所有数据?

时间:2016-06-24 11:36:11

标签: javascript jquery json

我有这个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调用中返回的Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown If e.KeyCode = Keys.Capital Then CheckBox1.Checked = Not CheckBox1.Checked End If End Sub 。我可以访问数据并显示html页面中的所有商店。

如何正确阅读?

1 个答案:

答案 0 :(得分:0)

// 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]);
 }
})