Hi I am having trouble deserializing my JSON object and displaying in a DataSet.
I have had partial success in that I am displaying most of the data except for the data that is contained in nested arrays.
What I have done is deserialize the data into a generic list and then from that list have converted it into a dataset which I will insert into a database. I am using JSON.net, more specifically the JsonConvert class to deserialize the string and then using a helper class to convert it to a dataset, which I stole from here and modified From Here. Now this works well until I hit the nested arrays.
On the first array I can see the data being returned in the XML but it does not appear in the returned dataset and the other array simply does not feature in the request at all.
I am handling the first array as below:
public List<string> Categories { get; set; }
This is what was as per json2csharp and it partially works in that I can see the categories options change depending on how many I select. For instance if i select 4 it will return 4 but the rows will be empty.
After I click on Categories it displays these 4 rows.
Any ideas on how i can get around this?
My second array is not being requested or returned at all. I have created a seperate class to handle the elements as below:
public class EventDate { public DateTime EndDate { get; set; } public DateTime StartDate { get; set; } }
and call it using this:
public List EventDates { get; set; }
This produces the error Column requires a valid Data Type
I have seen some examples that say you have to deserialize these using custom converters and others that say you should be able to do as I have done above. The format for the above are as per the json2charp website.
I have tried accessing the Categories as a string array but the same issue arose where I could see the returned data in the XML but not in the dataset.
Below I have included the deserializejson class that uses the Jsonconvert class to deserialize the jsonstring.
public List<RootObject> DeSerializeJsonString(string jsonString) { List<RootObject> list = new List<RootObject>(); list = (List<RootObject>)JsonConvert.DeserializeObject<List<RootObject>>(jsonString); return list; }
Any help would be greatly appreciated, cheers.