Parsing multi dimensional json in classic asp

Parsing multi dimensional json in classic asp

Had to do some new stuff to our old classic asp site. Wrote a SQL query which returned json, this had to be parsed and put into a Google graph component.

Spent a shit load of time to get to know aspJson and figure out how to get my data.

This is what worked

{
    "places": [
        {
            "placeid": 9210,
            "total": 38,
            "cols": [
                {
                    "webbooking": false,
                    "walkin": false,
                    "beskrivelse": "Manual",
                    "frasenavn": "manual",
                    "farve": "#3366cc",
                    "results": 21,
                    "personer": 1093,
                    "placeid": 9210
                },
                {
                    "webbooking": true,
                    "walkin": false,
                    "beskrivelse": "Online",
                    "frasenavn": "online",
                    "farve": "#109618",
                    "results": 12,
                    "personer": 62,
                    "placeid": 9210
                },
                {
                    "webbooking": true,
                    "walkin": false,
                    "beskrivelse": "Reference",
                    "frasenavn": "google_my_business",
                    "farve": "#ea4335",
                    "results": 2,
                    "personer": 5,
                    "placeid": 9210
                },
                {
                    "webbooking": true,
                    "walkin": false,
                    "beskrivelse": "Reference",
                    "frasenavn": "facebook",
                    "farve": "#3c5a98",
                    "results": 1,
                    "personer": 4,
                    "placeid": 9210
                },
                {
                    "webbooking": true,
                    "walkin": false,
                    "beskrivelse": "Reference",
                    "frasenavn": "instagram",
                    "farve": "#ed02d9",
                    "results": 2,
                    "personer": 35,
                    "placeid": 9210
                }
            ]
        }
    ]
}

This is what I wrote to get the Results row out for each occurence:

 oJson.loadJSON(oDb.RS("BookingOriginJson"))
            response.write oJson.JSONoutput
            for each place in oJson.data("places")
                for each coldata in oJson.data("places")(place).item("cols")
                    'for each test in oJson.data("places")(place).item("cols").item(coldata)
                        'response.write("<br>" & test & ": " & oJson.data("places")(place).item("cols").item(coldata).item(test))
                        response.write("<br>" & oJson.data("places")(place).item("cols").item(coldata).item("results"))
                    'next
                next
                response.write("<br>------------------------------")
            next