- Home /
Getting data out of Dictionary
So I am checking out the Gamedonia back end services and running into issues with Dictionary. I have never used data like this before, but the Gamedonia API queries return an Ilist of Dictionary items. Here is the JSON structure I am retrieving.
{
"name":"ItemName",
"number":2,
"position": [10,-4]
}
So using a a key will return one of these values as an object despite their database types being String, Integer, and Array. I am able to cast the single value objects it seems. I am having trouble with using the arrays though. I just cannot seem to be able to get the integers out of the array. Here is my retrieval code.
GamedoniaData.Search("buildings", "{\"LocationName\":\"TestCity_1\"}", delegate (bool searchSuccess, IList list){
if (searchSuccess){
Dictionary<string, object> building = (Dictionary<string, object>) list[0];
int[] position = new int[2];
position = (int[])building["Position"];
}
});
No matter what I try I cannot seem to cast the object as an int[]. It would be even better if I could just take the Dictionary and convert it to a class. Let me know if anybody has experience with this kind of workflow. Thanks.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Casting objects in Unity using a local class of an object 2 Answers
How to get an object inside a json JsonUtility 0 Answers
C# cast object to gameobject not working 2 Answers
Using Json to store data for objects 1 Answer