LitJson Arrays and Dictionaries in C#

Hi,

I’m new to Unity and JSON and am trying to use the LitJson package in a C# Mono environment to read some JSON but having some trouble working out how to access the data Arrays and Dictionaries.

If I have something like:

string jsonDataString; // assume jsonDataString has an Array and Dictionary in it.

JsonData jsonDataObj = JsonMapper.ToObject (jsonDataString);

how would I read the data from the jsonDataObj into an IList or IDictionary?

lol, this is super old, but since I’m messing with litjson again, i’ll take a stab at it.

you may be able to use List.AddRange() with the json stuff as a param…or you can do it manually. I did it manually when i did this before since i only needed a few of the items. this is how it looks

JsonData arrayOfStuff = jd["someArray"];//should be an array of items
		int itemCnt = arrayOfStuff.Count; 
			
		for(int i = 0; i < itemCnt; i++)
		{
			list.Add( (string)arrayOfStuff[i]["someField"]);			
		}