2017-06-06 99 views
1
[ 
    { 
    "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從JSON獲取關鍵的API請求

我需要訪問這些預約時段的ID,如5908e342236dee7e73646a44,這樣我就可以在API request

我把它使用角度。

回答

1

嘗試使用

var jsonObject = angular.fromJson(yourJsonString)

,將改變您的JSON的對象。然後,您可以迭代對象的任何字段並獲取鍵或值。

angular.forEach(jsonObject.whatever, function(value, key) { 
    console.log('key : ', key); 
    console.log('value : ', value); 
}); 
+0

感謝隊友那工作 –