I know there are several problem with json but nothing as same as to me. My problem
How to convert this jsonString to c# object. I've tried several time. This unexpected problem made me frustrated. I need to know whats problem with me and what should i do....
{ "status": 200, "status_messages": "Success ", "data": [ { "Alarm And Alert": [ { "0": "1", "1": "Alarm And Alert 1", "2": "0", "id": "1", "name": "Alarm And Alert 1", "islock": "0" }, { "0": "6", "1": "Alarm And Alert 6", "2": "0", "id": "6", "name": "Alarm And Alert 6", "islock": "0" } ] }, { "Animal": [ { "0": "7", "1": "Bird", "2": "0", "id": "7", "name": "Bird", "islock": "0" }, { "0": "13", "1": "Funny Animals", "2": "0", "id": "13", "name": "Funny Animals", "islock": "0" } ] }, { "Dj": [ { "0": "14", "1": "Dj 1", "2": "0", "id": "14", "name": "Dj 1", "islock": "0" }, { "0": "15", "1": "Dj 2", "2": "0", "id": "15", "name": "Dj 2", "islock": "0" }, { "0": "18", "1": "Dj 5", "2": "0", "id": "18", "name": "Dj 5", "islock": "0" } ] }, { "Rap": [ { "0": "71", "1": "Rap Ringtones 1", "2": "0", "id": "71", "name": "Rap Ringtones 1", "islock": "0" }, { "0": "77", "1": "Rap Ringtones 7", "2": "0", "id": "77", "name": "Rap Ringtones 7", "islock": "0" } ] } ] }
My Class:
public class Category
{
public string __invalid_name__0 { get; set; }
public string id { get; set; }
public string __invalid_name__1 { get; set; }
public string name { get; set; }
public string __invalid_name__2 { get; set; }
public string islock { get; set; }
}
public class CategoryCollection
{
public List<category> CategoryRingtone { get; set; }
}
public class RootObject
{
public int status { get; set; }
public string status_messages { get; set; }
public List<categorycollection> data { get; set; }
}
categoriesJsonString = await Downloader.LoadCategoriesFromServer();
RootObject rootObject = new RootObject();
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(categoriesJsonString));
DataContractJsonSerializer ser = new DataContractJsonSerializer(rootObject.GetType());
rootObject = ser.ReadObject(ms) as RootObject;
ms.Close();