Getting data out of JSON

Hi,

I can succesfully get JSON from server but I’m having trouble parsing data out of it.
This is my example data:

{  
   "key":73206,
   "name":"Company",
   "folders":[  
      {  
         "key":73407,
         "name":"Osasto1",
         "surveys":[  
            {  
               "key":406793,
               "question":{  
                  "key":55639,
                  "name":"What is happening?",
                  "locale":"en-US"
               },
               "timeZone":"Europe/Helsinki",
               "activePeriods":[  
                  {  
                     "start":"2018-03-29T00:00:00.000+03:00",
                     "end":"2030-01-02T00:00:00.000+02:00"
                  }
               ],
               "surveyType":"TERMINAL"
            }
         ]
      },
      {  
         "key":73406,
         "name":"Osasto2",
         "surveys":[  
            {  
               "key":406794,
               "question":{  
                  "key":55639,
                  "name":"Say something?",
                  "locale":"en-US"
               },
               "timeZone":"Europe/Helsinki",
               "activePeriods":[  
                  {  
                     "start":"2018-03-29T00:00:00.000+03:00",
                     "end":"2030-01-02T00:00:00.000+02:00"
                  }
               ],
               "surveyType":"TERMINAL"
            }
         ]
      }
   ]
}

So from every folder I need “name” and from every survey there I need “key” and question “name”.
I’ve managed to get this JSON to nested dictionary but it did not help me to figure this out…

Thanks for any direction!

Jukka

Assuming the new framework…

dim json as Xojo.Core.Dictionary = _
    Xojo.Data.ParseJSON( jsonText )
dim folders() as auto = json.Value( "folders" )
for each folder as Xojo.Core.Dictionary in folders
  dim name as text = folder.Value( "name" )
  dim surveys() as auto = folder.Value( "surveys" )
  for each survey as Xojo.Core.Dictionary in surveys
    dim key as text = survey.Value( "key" )
    // ... and so on
  next
next

Thank You, works perfectly.

And there’s one more thing :slight_smile:

This outer array has no value name? And “data” is only values…

[ 
{
"ts": "2016-06-01T00:00:00.000Z", "data": [4,8,12,16]
},
{
"ts": "2016-05-02T00:00:00.000Z", "data": [7,5,23,37]
}
]

Jukka

Ok, got it :slight_smile:

  dim results() as auto = Xojo.Data.ParseJSON( buffer )
  for each result as Xojo.Core.Dictionary in results
    dim data() as auto = result.Value( "data" )
  next