Answer the question
In order to leave comments, you need to log in
How to serialize list of class type?
I need to serialize the list of the RootObject class, I tried a lot, I can’t serialize, I visited a simple record, the file doesn’t come out, can you tell me even?
public class Section
{
public string type { get; set; }
public string group { get; set; }
public int count { get; set; }
public string name { get; set; }
public string displaytype { get; set; }
public List<object> data { get; set; }
}
public class RootObject
{
public string xmlns { get; set; }
public string status { get; set; }
public string version { get; set; }
public int webplayer { get; set; }
public string responsetype { get; set; }
public List<Section> sections { get; set; }
}
var obj = JsonConvert.DeserializeObject<RootObject>(bn);
Answer the question
In order to leave comments, you need to log in
To serialize a list, you need to make sure that your Section class is also serializable. If it's serializable - at least you can serialize each element of the list in turn in a loop.
JsonConvert.SerializeObject(new RootObject().sections);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question