c# - Serialize an object using DataContractJsonSerializer as a json array -


I have a class in which there is a list of items. I use DataContractJsonSerializer as a JSON array I want to serial an example of the class. E.g.

class MyClass {list & lt; MyItem & gt; _items; } Class MyItem {public string name {get; Set;} public string description {get; Set;}} When json is serialized, it should be like this:

<{"name": "one", "Description": "desc1"}, {"name": "two", "description": "desc2"}]

  [dataContact] public class MyItem {[DataMember] public string name {get; Set; } [Datamember] public string description {get; Set; }} Class program {static zero main () {var graph = new list & lt; MyItem & gt; {New MyItem {name = "one", description = "desc1"}, new MyItem {name = "two", description = "desc2"}}; Var serializer = New DataContractJsonSerializer (graph.GetType ()); Serializer.WriteObject (Console.OpenStandardOutput (), Graph); }}  

Comments