Hello,
I need help enumerating a dictionary value that is of type List<List>, I want the content within the value which consist of a list of ones and zeros which define the structure of the level.
I am approaching this by getting the key “level” which returns an object. I then try to assign that value of type object to a list, so I type cast it to List<List> so i can then enumerate and structure the level based on what that value returns. The problem is that before I even begin enumerating the key “level”, the list that is assigned the key value “level” returns null.
Here is a function to test out some values, since it returns null I did not bother to actually try and enumerate the level until I find a proper way of getting the dictionary value without it returning null.
void Test(){
/* Here is the content of the Level_1 JSON file
I would like to enumerate the ones and zeros
"level" : [ [1, 1, 1, 1, 1, 1, 1, 1, 1 ],
[0, 0, 1, 1, 1, 1, 1, 0, 0 ],
[1, 1, 1, 1, 1, 1, 1, 1, 1 ],
[1, 1, 1, 1, 1, 1, 1, 1, 1 ],
[0, 0, 0, 1, 1, 1, 0, 0, 0 ],
[1, 1, 1, 1, 1, 1, 1, 1, 1 ],
[1, 1, 1, 1, 1, 1, 1, 1, 1 ],
[1, 1, 1, 0, 0, 0, 1, 1, 1 ],
[1, 1, 1, 0, 0, 0, 1, 1, 1 ] ],
"score" : 10,
*/
// Helper method, takes Json file and deserializes it as Dictionary<string,dynamic>
// The dictionary value is of type dynamic because the json file contains a list and an int, idk if this might be a problem
Dictionary<string,dynamic> dictionary = LoadJSONFile("Level_1");
// Get level key value, have to type cast to List<List<int>> else it returns of type object
var level = dictionary["level"] as List<List<int>>;
var newList = new List<List<int>>(level); // This returns null
// Get score key value
var score = dictionary["score"];
// Get level key value
var rawLevel = dictionary["level"];
Debug.Log("score is: " + score); // Logs: score is: 10
Debug.Log("level: " + newList); // returns null, error message: Argument cant be null
Debug.Log("raw level: " + rawLevel); // Logs: System.Collections.Generic.List`1[System.Object]
}
Thanks in advance.