InfluxDB JSON响应格式

时间:2018-11-20 08:46:25

标签: javascript html json

我收到来自influxdb http查询的JSON响应,如下所示:

{
    "results": [{
        "statement_id": 0,
        "series": [{
            "name": "healthCheckTestV1",
            "columns": ["time", "transactionName", "responseTime"],
            "values": [
                ["2018-11-20T08:09:50.4799222Z", "Security_Question", 4.167099],
                ["2018-11-20T08:09:50.0868723Z", "File_Download", 4.867642],
                ["2018-11-20T08:09:49.6968331Z", "View_File", 9.709544],
                ["2018-11-20T08:09:49.3077855Z", "Open_TEAM", 18.121819],
                ["2018-11-20T08:09:48.9147399Z", "File_Upload", 9.891604],
                ["2018-11-20T08:09:47.0675403Z", "Open_OneDrive", 2.793456],
                ["2018-11-20T08:09:46.5719031Z", "Logout", 11.781315],
                ["2018-11-20T08:08:06.0374685Z", "Login_OKTA", 7.293168],
                ["2018-11-20T08:07:49.8022407Z", "HomePage", 3.037265]
            ]
        }]
    }]
}

我想以以下格式在JavaScript中显示以上内容。

 File_Download   9
 View_File       8
 Open_TEAM       7
 Open_OneDrive   6
 File_Upload     5
 File_Download   4

我对JavaScript / json完全陌生。赞赏有人可以帮助我。非常感谢

我的尝试:

var response = getResponse();
for (var i = 0; i < response.results.length; i++) {
  for (var t = 0; t < response.results[i].series.length; t++) {
    console.log(response.results[i].series[t].columns);
    console.log("**********************************************");
    for (var j = 0; j < response.results[i].series[t].values.length; j++) {
      console.log(response.results[i].series[t].values[j])
    }
  }
}

function getResponse() {
  return {
    "results": [{
      "statement_id": 0,
      "series": [{
        "name": "healthCheckTestV1",
        "columns": ["time", "transactionName", "responseTime"],
        "values": [
          ["2018-11-20T08:09:50.4799222Z", "Security_Question", 4.167099],
          ["2018-11-20T08:09:50.0868723Z", "File_Download", 4.867642],
          ["2018-11-20T08:09:49.6968331Z", "View_File", 9.709544],
          ["2018-11-20T08:09:49.3077855Z", "Open_TEAM", 18.121819],
          ["2018-11-20T08:09:48.9147399Z", "File_Upload", 9.891604],
          ["2018-11-20T08:09:47.0675403Z", "Open_OneDrive", 2.793456],
          ["2018-11-20T08:09:46.5719031Z", "Logout", 11.781315],
          ["2018-11-20T08:08:06.0374685Z", "Login_OKTA", 7.293168],
          ["2018-11-20T08:07:49.8022407Z", "HomePage", 3.037265]
        ]
      }]
    }]
  };
}

输出如下:

[ 'time', 'transactionName', 'responseTime' ]
**********************************************
[ '2018-11-20T09:16:15.1442021Z', 'Security_Question', 3.750389 ]
[ '2018-11-20T09:16:14.7631577Z', 'File_Download', 5.369951 ]
[ '2018-11-20T09:16:13.9440692Z', 'View_File', 13.827224 ]
[ '2018-11-20T09:16:13.3379987Z', 'Open_TEAM', 17.779691 ]
[ '2018-11-20T09:16:12.9609559Z', 'File_Upload', 38.956707 ]
[ '2018-11-20T09:16:12.5737327Z', 'Open_OneDrive', 2.949066 ]
[ '2018-11-20T09:16:12.0929475Z', 'Logout', 11.773299 ]
[ '2018-11-20T09:13:50.9144754Z','Login_OKTA',6.6948170000000005 ]
[ '2018-11-20T09:13:36.2807192Z', 'HomePage', 2.719711 ]

0 个答案:

没有答案