I must be totallt stupid but below json does not work for me to parse:
{
"code": 200,
"data": {
"items": [
{
"title": "test 0"
},
{
"title": "test 1"
}
]
}
}
I use the following code to do this:
Dim JSON As JSONParser
Dim jsonMap As Map
Dim jsonResultMap As Map 'helper map for navigating
Dim jsonItems As List
'initialize json
JSON.Initialize(File.ReadString(File.DirAssets, "example1.json"))
'get objects
jsonMap = JSON.NextObject
'get data object for non array items
jsonResultMap=jsonMap.Get("data")
'move to next object from data structure
'or use a list for arrays
'jsonResultMap=jsonResultMap.Get("data")
jsonItems = jsonResultMap.Get("items")
For i = 0 To jsonItems.Size - 1
jsonItems = jsonItems.Get(i)
Log(jsonItems.Get("title"))
Next
{
"code": 200,
"data": {
"items": [
{
"title": "test 0"
},
{
"title": "test 1"
}
]
}
}
I use the following code to do this:
Dim JSON As JSONParser
Dim jsonMap As Map
Dim jsonResultMap As Map 'helper map for navigating
Dim jsonItems As List
'initialize json
JSON.Initialize(File.ReadString(File.DirAssets, "example1.json"))
'get objects
jsonMap = JSON.NextObject
'get data object for non array items
jsonResultMap=jsonMap.Get("data")
'move to next object from data structure
'or use a list for arrays
'jsonResultMap=jsonResultMap.Get("data")
jsonItems = jsonResultMap.Get("items")
For i = 0 To jsonItems.Size - 1
jsonItems = jsonItems.Get(i)
Log(jsonItems.Get("title"))
Next