0

I'm trying to get the values of these keys from this json response:

{
    "wlan": {
        "channel": 1,
        "ssid": "WLAN-25UR7J",
        "mac": "00:17:91:80:22:96",
        "inet": [
            {
                "netmask": "255.255.255.0",
                "ip": "192.168.2.112",
                "family": "IPv4"
            }
        ],
        "stationinfo": {
            "signal": -48,
            "channelwidth": 0,
            "bitrate": 72.2
        },
        "mode": "station",
        "encryption": "WPA2-PSK"
    }
}

I could get the values from wlan key by using this method.

json.decode(response.body)['wlan']['channel']

But I didn't work on the rest values like getting netmask or bitrate for example.

3
  • 2
    Have you tried using json.decode(response.body)['wlan']['inet'][0]['netmask']? Commented Sep 19, 2020 at 18:09
  • thanks a lot, no i didn't , it worked for inet key , but how please for stationinfo json.decode(response.body)['wlan']['inet'][1]['signal'] or json.decode(response.body)['wlan']['inet']['stationinfo'][0]['signal'] Commented Sep 19, 2020 at 18:45
  • ['wlan']['stationinfo']['signal'] worked great, thanks again Commented Sep 19, 2020 at 19:19

1 Answer 1

1

For netmask, you can access it like this:

json.decode(response.body)['wlan']['inet'][0]['netmask']

For bitrate, you can access it by:

json.decode(response.body)['wlan']['stationinfo']['bitrate']

If values inside any key is an array, either access them via index like value[0] or you can simply iterate the array and do the necessary action.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.