How to drill down into a nested object in Monkey C? (connect-iq)

351 views Asked by At

EMULATOR "fr945"

MIN API LEVEL "3.0.0"

API DATA STRUCTURE

{         
  "data": {
    "devices": [           
        {
            "device": "00:0E:00:AD:00:00:00:4A",
            "model": "H6008",
            "deviceName": "Mudroom",
            "controllable": true,
            "retrievable": true,
            "supportCmds": [
                "turn",
                "brightness",
                "color",
                "colorTem"
            ],
            "properties": {
                "colorTem": {
                    "range": {
                        "min": 2700,
                        "max": 6500
                    }
                }
            }
        }
      ]
    },
    "message": "Success",
    "code": 200
}

CODE

 if (args instanceof Dictionary) {

        var keys = args.keys();
        _message = "";
        for (var i = 0; i < keys.size(); i++) {
            _message += Lang.format("$1$: $2$\n", [keys[i], args[keys[i]]]);
        }
    }

When I run through the object, message and code print(and their values), but data does not. Even so, getting it to print wouldn't solve my issue, I am trying to drill into the data.devices[] array to be able to access the information in each array index. Ex: data.devices[0].dataName and print that information.

Is this even possible with Monkey C?

1

There are 1 answers

1
TimothyLuedtke On

Roughly figured it out-

       var devices = data["data"]["devices"];            
        var devicesSize = devices.size();


        for (var i = 0; i < devicesSize; i++) {
            var device = devices[i];
               Sys.println(device);