尝试使用密钥访问JSON对象

时间:2015-06-03 09:17:55

标签: jquery json

这是我将JSON存储在var

中的代码
var analysed Data = {
  "Wednesday": {
    "OTHERS": {
      "count": 1,
      "response Time": 234
    },
      "URGENT": {
      "count": 15,
      "response Time": 68
    },
      "NORMAL": {
      "count": 10,
      "response Time": 120
    }
  },
    "Thursday": {
    "OTHERS": {
      "count": 1,
      "response Time": 234
    },
      "URGENT": {
      "count": 15,
      "responseTime": 68
    },
      "NORMAL": {
      "count": 10,
      "responseTime": 120
    }
  },
  "Tuesday": {
    "OTHERS": {
      "count": 1,
      "response Time": 5
    },
      "URGENT": {
      "count": 15,
      "response Time": 68
    },
      "NORMAL": {
      "count": 10,
      "response Time": 120
    }
  }
}

问题:

请建议我使用key访问它们的方法。我需要获得每个关键字的响应时间,例如normal。这是紧急的,您的信息。

我应该使用jQuery实现这一点并添加响应时间以获取avg

1 个答案:

答案 0 :(得分:1)

如果您在JavaScript中有json对象,则可以访问键和值:

$.each(myObject, function (key, val) {

    // See key and value:
    alert(key + ': ' + val.URGENT.count);

    // See keys for each object:
    $.each(Object.keys(val), function (key, val) {
        alert(key + ': ' + val);
    });
});