简体   繁体   English

复杂的JSON数组

[英]Complex JSON-array

I have an Arduino Yun where I host a webpage. 我有一个Arduino Yun,我在其中托管一个网页。 Now I want to display the wifi signal quality on that page. 现在,我要在该页面上显示wifi信号质量。 I managed to dig in the system and I am able to pop up this JSON-like array 我设法在系统中进行挖掘,并且能够弹出这个类似于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
  ]
}

Unfortunately, this is the way it comes and I can't change it nor do I know how it is produced. 不幸的是,这就是它的实现方式,我无法更改它,也不知道它是如何产生的。

Is there a way to extract the bit that says "Quality": 70? 有没有一种方法可以提取“ Quality”(质量):70?

I tried it with the following code but no luck (it came back as undefined). 我用下面的代码尝试了一下,但是没有运气(它以未定义的形式出现)。 I used data[3] as it looks like multiple arrays and Quality is in the 4th one. 我使用了data [3],因为它看起来像多个数组,而Quality在第4个数组中。

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;
}
});
}

Try to parse it with a json parser (for instance http://json.parser.online.fr/ ) 尝试使用json解析器对其进行解析(例如http://json.parser.online.fr/

Then, you can follow the path for the quality: 然后,您可以遵循以下质量方针:

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

try this 尝试这个

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

The simplest way that works for me is just pasting this json into Chrome developer console like: data = { "conncount": 5, ... } . 对我来说,最简单的方法就是将json粘贴到Chrome开发者控制台中,例如: data = { "conncount": 5, ... } Chrome presents objects in a readable form. Chrome浏览器以可读的形式显示对象。 You can work your way through it with expanding collapsed objects/arrays. 您可以通过扩展折叠的对象/数组来完成此工作。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM