Archived Forum Post

Index of archived forum posts

Question:

Load JSON Array?

Jun 16 '16 at 08:24

Just curious how i load json string that starts as array [ ie

    [
       {
          "id":200
       },
       {
          "id":196
       }
    ]
At the moment i cheat a bit and prefix the string it with { "array": and post fix with } and then use jsonobject.load(string) It works, but i assume there is a correct way?


Answer

Your cheat is likely the best solution. A JSON object must begin with "{". See http://www.json.org/

An array is just one particular kind of value:

object {} { members } members pair pair , members pair string : value array [] [ elements ] elements value value , elements value string number object array true false null