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!