I
I
itgood2019-01-25 20:50:01
C++ / C#
itgood, 2019-01-25 20:50:01

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

2 answer(s)
P
Pavel, 2019-01-25
@youkerni

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.

L
LiptonOlolo, 2019-01-26
@LiptonOlolo

JsonConvert.SerializeObject(new RootObject().sections);

What is the problem?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question