复杂的JSON数组

时间:2016-02-03 14:07:47

标签: arrays json

我有一个Arduino Yun,我主持一个网页。现在我想在该页面上显示wifi信号质量。我设法挖掘系统,我能够弹出这个类似JSON的数组

{
  "conncount": 5,
  "leases": {

  },
  "wan": {
    "proto": "dhcp",
    "ipaddr": "192.168.0.13",
    "link": "/cgi-bin/luci/;stok=235c7aba0f5cbf5cf752ad119ece74e6/admin/network/network/lan",
    "netmask": "255.255.255.0",
    "gwaddr": "192.168.0.1",
    "expires": -1,
    "uptime": 4407,
    "ifname": "wlan0",
    "dns": [
      "192.168.0.1"
    ]
  },
  "membuffers": 15708,
  "connmax": 16384,
  "memfree": 1576,
  "uptime": 4481,
  "wifinets": [
    {
      "device": "radio0",
      "networks": [
        {
          "ifname": "wlan0",
          "encryption": "WPA2 PSK (CCMP)",
          "bssid": "04:A1:51:D3:BC:E8",
          "mode": "Client",
          "quality": 70,
          "noise": -95,
          "ssid": "Skynet-ITA",
          "link": "/cgi-bin/luci/;stok=235c7aba0f5cbf5cf752ad119ece74e6/admin/network/wireless/radio0.network1",
          "assoclist": {
            "04:A1:51:D3:BC:E8": {
              "rx_short_gi": true,
              "noise": -95,
              "rx_mcs": 7,
              "tx_40mhz": true,
              "rx_40mhz": true,
              "tx_rate": 135000,
              "tx_packets": 14825,
              "tx_short_gi": true,
              "rx_packets": 101935,
              "tx_mcs": 6,
              "inactive": 360,
              "rx_rate": 150000,
              "signal": -61
            }
          },
          "txpoweroff": 0,
          "bitrate": 135,
          "txpower": 16,
          "name": "Client \u0022Skynet-ITA\u0022",
          "channel": 6,
          "country": "NL",
          "signal": -61,
          "up": true,
          "frequency": "2.437"
        }
      ],
      "name": "Generic 802.11bgn Wireless Controller (radio0)",
      "up": true
    }
  ],
  "memtotal": 61116,
  "localtime": "Wed Feb  3 12:09:13 2016",
  "memcached": 17596,
  "loadavg": [
    0.04052734375,
    0.125,
    0.20263671875
  ]
}

不幸的是,这是它的方式,我不能改变它,也不知道它是如何产生的。

有没有办法提取出“质量”的位:70?

我尝试使用以下代码但没有运气(它以未定义的形式返回)。我使用数据[3],因为它看起来像多个数组,质量是第四个。

var q;

$(document).ready(function() {
var refresh = setInterval(getData, 5000);
});

function getData() {
$.ajax({
        type: "POST",
        url: "/cgi-bin/luci/;stok=6ea83154346f9c42e99ac14ae8856b2b?status=1&_=0.16447926725451678",
        dataType: "JSON",
        cahce: "false",
        success: function(data){
        q  = data[3].quality;
}
});
}

3 个答案:

答案 0 :(得分:3)

尝试使用json解析器解析它(例如http://json.parser.online.fr/

然后,您可以按照质量路径:

data.wifinets[0].networks[0].quality

答案 1 :(得分:1)

试试这个

 var quality=data['wifinets'][0]['networks'][0]['quality'];
 alert(quality);

答案 2 :(得分:1)

对我来说最简单的方法就是将这个json粘贴到Chrome开发者控制台中,例如:data = { "conncount": 5, ... }。 Chrome以可读的形式呈现对象。您可以通过展开折叠的对象/数组来完成它。

enter image description here