Serialize an object using DataContractJsonSerializer as a json array

Posted by rekna on Stack Overflow See other posts from Stack Overflow or by rekna
Published on 2010-05-16T16:17:00Z Indexed on 2010/05/16 16:20 UTC
Read the original article Hit count: 186

I have a class which contains a list of items. I want to serialize an instance of this class to json using the DataContractJsonSerializer as a json array. eg.

class MyClass 
{
    List<MyItem> _items;
}

class MyItem
{
   public string Name {get;set;}
   public string Description {get;set;}
}

When serialized to json it should be like this :

[{"Name":"one","Description":"desc1"},{"Name":"two","Description":"desc2"}]

© Stack Overflow or respective owner

Related posts about datacontractserializer

Related posts about JSON