LitJSON: Unable to use foreach

I’m using LitJSON to load .json data, and I’m running some test code with a foreach loop, but it’s not working.

Error:
InvalidOperationException: Instance of JsonData is not a dictionary
LitJson.JsonData.EnsureDictionary()
(line 12 in the example below)

    using UnityEngine;
    using LitJson;
    using System.Collections;
    using System.Collections.Generic;
    using System.IO;

    public void LoadData() {
        JsonReader reader = new JsonReader("[1, 2, 3, 4, 5]");
        JsonData data = JsonMapper.ToObject(reader);

        foreach (JsonData i in data) {
          Debug.Log("foreach: test");
        }
    }

According to the example in the documentation (Ctrl+F “foreach”; it’s near the bottom of the page), I’m pretty sure this code should work (?).

Anyone have any ideas as to why this wouldn’t work? Advice would be greatly appreciated!

I am having the same issue.
Were you able to fix it?

It’s an array, not a dictionary - maybe try looping through it by index instead of by foreach.

for (int i=0; i<data.Count; i++) {
Debug.Log("data["+i+"] = "+data[i]);
}