-4

Now I am using vibed JSON module, but I do not know how to get access to nested elements without iteration it with foreach.

Here is my JSON:

{
    "hasMore": false,
    "result": [{
        "ip": "127.0.0.1",
        "passedtests": "[firsttest8,firsttest8,firsttest8,firsttest8]",
        "guid": ""
    }],
    "code": 201,
    "extra": {
        "stats": {
            "writesIgnored": 0,
            "scannedIndex": 0,
            "scannedFull": 1,
            "executionTime": 0,
            "filtered": 0,
            "writesExecuted": 0
        },
        "warnings": []
    },
    "error": false,
    "cached": false
}

I would like to do something like: result.passedtests. But here result is an array.

Nofi
  • 2,107
  • 1
  • 15
  • 23
Dmitry Bubnenkov
  • 9,415
  • 19
  • 85
  • 145
  • *I do not know how to get access to nested elements without iteration it with foreach.* why is foreach a problem? – Tim May 09 '16 at 10:36

1 Answers1

-1

I found perfect solution:

Json resultPassedtestsJson = visitorsInfo["result"][0]["passedtests"]; // "[firsttest8,firsttest8,firsttest8,firsttest8]"

[0] is because result is array, and we access to it's first element.

Dmitry Bubnenkov
  • 9,415
  • 19
  • 85
  • 145