从JSON获取API请求的密钥

时间:2017-06-06 08:34:40

标签: angularjs json

[
  {
    "docId": "58d8f38cd2f554fdfca4fd18",
    "__v": 8,
    "clinicDetails": {
      "5908e342236dee7e7364698e": {
        "appointmentSlots": {
          "sat": {
            "5908e342236dee7e73646a44": {
              "bookFlag": true,
              "endTime": "07:00PM",
              "startTime": "06:30PM"
            },
            "5908e342236dee7e73646a43": {
              "bookFlag": true,
              "endTime": "06:30PM",
              "startTime": "06:00PM"
            },
.......

完整档案 https://docs.google.com/document/d/1FK1NEY1Vmjzv2gBtleFquA0VMpfYGf9FaMyblPr8vws/edit?usp=sharing

我需要访问5908e342236dee7e73646a44这些约会广告位ID,以便我可以API request

发送

我正在使用棱角分明。

1 个答案:

答案 0 :(得分:1)

尝试使用

var jsonObject = angular.fromJson(yourJsonString)

这会将你的Json变换为一个对象。然后,您可以在对象的任何字段上迭代获取键或值。

angular.forEach(jsonObject.whatever, function(value, key) {
  console.log('key : ', key);
  console.log('value : ', value);
});
相关问题