how do you Deserialize JSON in a list?
Hello, I have a question about JSON files and Deserialization. I'm using Unity and the MinJson library to Deserialize the information passed over by the Graph API with C#. Currently I can Deserialize arrays or individual items in a format like this.
"category_list": [{"id": "205950169432461","name": "Day Spa"}] "information" : "information that this holds"
what i'm having an issue with is when the Json is in a format such as this I believe they are called lists (please correct me if I'm wrong) :
"hours"{"day one": "time", "day_two": "time2", "day_three": "time3" }
What i'm doing to deserialize is this:
//IResult being the Json information about the page passed by the Graph API
public void DisplayBusinessInfo (IResult result)
{
String JsonString = result.RawResult;
var PageInfo = Json.Deserialize(JsonString) as Dictionary<string, object>;
//using the array example above
List<object> categorylist = PageInfo["category_list"] as List<object>;
}
try
{
// this for loop breaks down the list that I stored categorylist into and returns the individual items within it
for (int i = 0; i < categorylist.Count; i++)
{
Dictionary<string, object> messageData = categorylist[i] as Dictionary<string, object>;
object resultData = messageData["name"];
Debug.Log("JSON string : " + resultData.ToString());
//returns the information : Day Spa
}
catch
{
Debug.Log("it is done");
}
//anything that is not an array goes directly into this if statement. Again i'll use the example I have provided above
if (result.Error == null)
{
Information = "" + result.ResultDictionary["information"];
//Returns : information that this holds
}
What I don't understand about the list is how it's being classified in Deserialization. I have tried passing it through as an object and string but failed on both attempts. If you could help explain what Json information in {} is and provide a link or any help on deserializing it with the format I have currently, I would greatly appreciate it!
Your answer
Follow this Question
Related Questions
Argument Exception: J SON must represent an object type. Serialization list of objects 0 Answers
How to read a nested Array Json File in unity 3d? 0 Answers
How do you sort a list of JSONNodes by key value? 1 Answer
How To Deserialize Json Data Into List? 1 Answer
Facebook SDK Json Parsing with foreach loop not updating 1 Answer