JSON Parsing

Nyptop

Active Member
Licensed User
Longtime User
Could anybody show me how to parse the following JSON:

B4X:
[
    {
        "category": "burglary", 
        "month": "2012-04", 
        "location": {
            "latitude": "52.6391872", 
            "street": {
                "id": 883491, 
                "name": "On or near Mantle Road"
            }, 
            "longitude": "-1.1507308"
        }, 
        "context": "", 
        "id": 8816657, 
        "location_type": "Force",
        "outcome_status": {
            "category": "Under investigation", 
            "date": "2012-04"
        }
    },
    {
        "category": "other-crime", 
        "month": "2012-04", 
        "location": {
            "latitude": "52.6341420", 
            "street": {
                "id": 883564, 
                "name": "On or near Bolton Road"
            }, 
            "longitude": "-1.1580392"
        }, 
        "context": "", 
        "id": 8820409, 
        "location_type": "Force",
        "outcome_status": {
            "category": "Under investigation", 
            "date": "2012-04"
        }      
    },
    {
        "category": "anti-social-behaviour", 
        "month": "2012-04", 
        "location": {
            "latitude": "52.6313999", 
            "street": {
                "id": 1321347, 
                "name": "Leicester"
            }, 
            "longitude": "-1.1252999"
        }, 
        "context": "", 
        "id": 8389368, 
        "location_type": "BTP"
    }
    ...
]

Cheers,

Neil

P.S Here is the website: Street-level crimes - Police API
 
Last edited:

hdtvirl

Active Member
Licensed User
Longtime User
Are you missing a ']' at the end of your json file.

you can check your JSON arrays using this validator site.

JSON Formatter & Validator

JSON.


Take a look at this tutorial, look at this part in particular.

Dim rows As List
rows = parser.NextArray

'work with result
'rows is a List. Each item is a Map with the columns names as keys and the db values as the values.
For i = 0 To rows.Size - 1
Log("Rows #" & i)
Dim m As Map
m = rows.Get(i)
Log("col1=" & m.Get("col1")) 'log the values of col1 and col2
Log("col2=" & m.Get("col2"))
Next


Regards

BOB
 
Last edited:
Upvote 0

Nyptop

Active Member
Licensed User
Longtime User
Thanks for the help BOB,

I still haven't managed to fix the problem though. I'm exactly sure what 'ArrayIndexOutOfBounds' means in my context, and I think this is where my solution lies.

Cheers,

Neil
 
Upvote 0
Top