我知道json有几个问题,但没有和我一样。我的问题 如何将此jsonString转换为c#对象。我试了好几次。这个意外的问题让我感到沮丧。我需要知道我的问题,我该怎么做......
{ “身份”:200, “status_messages”:“成功”, “数据”:[ { “警报和警报”:[ { “0”:“1”, “1”:“警报和警报1”, “2”:“0”, “id”:“1”, “名称”:“警报和警报1”, “islock”:“0” }, { “0”:“6”, “1”:“警报和警报6”, “2”:“0”, “id”:“6”, “名称”:“警报和警报6”, “islock”:“0” } ] }, { “动物”:[ { “0”:“7”, “1”:“鸟”, “2”:“0”, “id”:“7”, “名字”:“鸟”, “islock”:“0” }, { “0”:“13”, “1”:“有趣的动物”, “2”:“0”, “id”:“13”, “名字”:“有趣的动物”, “islock”:“0” } ] }, { “Dj”:[ { “0”:“14”, “1”:“Dj 1”, “2”:“0”, “id”:“14”, “名字”:“Dj 1”, “islock”:“0” }, { “0”:“15”, “1”:“Dj 2”, “2”:“0”, “id”:“15”, “名字”:“Dj 2”, “islock”:“0” }, { “0”:“18”, “1”:“Dj 5”, “2”:“0”, “id”:“18”, “名字”:“Dj 5”, “islock”:“0” } ] }, { “说唱”:[ { “0”:“71”, “1”:“Rap Ringtones 1”, “2”:“0”, “id”:“71”, “名字”:“Rap Ringtones 1”, “islock”:“0” }, { “0”:“77”, “1”:“Rap Ringtones 7”, “2”:“0”, “id”:“77”, “名字”:“Rap Ringtones 7”, “islock”:“0” } ] } ] }
我的班级:
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();
答案 0 :(得分:0)
public class AlarmAndAlert
{
public string __invalid_name__0 { get; set; }
public string __invalid_name__1 { get; set; }
public string __invalid_name__2 { get; set; }
public string id { get; set; }
public string name { get; set; }
public string islock { get; set; }
}
public class Animal
{
public string __invalid_name__0 { get; set; }
public string __invalid_name__1 { get; set; }
public string __invalid_name__2 { get; set; }
public string id { get; set; }
public string name { get; set; }
public string islock { get; set; }
}
public class Dj
{
public string __invalid_name__0 { get; set; }
public string __invalid_name__1 { get; set; }
public string __invalid_name__2 { get; set; }
public string id { get; set; }
public string name { get; set; }
public string islock { get; set; }
}
public class Rap
{
public string __invalid_name__0 { get; set; }
public string __invalid_name__1 { get; set; }
public string __invalid_name__2 { get; set; }
public string id { get; set; }
public string name { get; set; }
public string islock { get; set; }
}
public class Datum
{
public List<AlarmAndAlert> __invalid_name__Alarm And Alert { get; set; }
public List<Animal> Animal { get; set; }
public List<Dj> Dj { get; set; }
public List<Rap> Rap { get; set; }
}
public class RootObject
{
public int status { get; set; }
public string status_messages { get; set; }
public List<Datum> data { get; set; }
}