从JSON获取密钥以进行API请求 [英] Get key from JSON for API request

查看:149
本文介绍了从JSON获取密钥以进行API请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[
  {
    "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/1FK1NEY1Vmjzv2gBtle edit?usp = sharing

我需要访问这些约会插槽ID,例如5908e342236dee7e73646a44,以便可以在API request

I need to access these appointment slot ids like 5908e342236dee7e73646a44, so that I can send it in an API request

我正在使用角度.

推荐答案

尝试使用

var jsonObject = angular.fromJson(yourJsonString)

这会将您的Json转换为对象.然后,您可以遍历对象的任何字段以获取键或值.

That will transform your Json to an object. Then you can iterate over any field of the object an get keys or values.

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

这篇关于从JSON获取密钥以进行API请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆