简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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