Using system;
Using system. Collections. Generic;
Using system. text;
Using newtonsoft. JSON. converters;
Using newtonsoft. JSON;
Using system. Data;
Using system. Data. SQLite;
Namespace consoleapplication2
{
Class Program
{
Static void main (string [] ARGs)
{
Product = new product ();
Product. Name = "[] {}\\'' \" \ "apple ";
Product. Expiry = new datetime (2008, 12, 28 );
Product. Price = 3.99 m;
Product. Sizes = new string [] {"small", "medium", "large "};
String output = javascriptconvert. serializeobject (product );
Console. writeline ("product :");
Console. writeline (output );
// {// "Name": "apple", // "Expiry": new date (1230422400000), // "price": 3.99, // "sizes ": [// "small", // "medium", // "large" //] //}
Product deserializedproduct = (product) javascriptconvert. deserializeobject (output, typeof (product ));
String [] values = new string [] {"small", "medium", "large "};
Output = javascriptconvert. serializeobject (values );
Console. writeline ("strings :");
Console. writeline (output );
String [] deserializedstring = (string []) javascriptconvert. deserializeobject (output, typeof (string []);
}
}
Public class product
{
Private string _ name;
Public string name
{
Get {return _ name ;}
Set {_ name = value ;}
}
Private datetime _ expiry;
Public datetime expiry
{
Get {return _ expiry ;}
Set {_ expiry = value ;}
}
Private decimal _ price;
Public decimal price
{
Get {return _ price ;}
Set {_ price = value ;}
}
Private string [] _ sizes;
Public String [] sizes
{
Get {return _ sizes ;}
Set {_ sizes = value ;}
}
}
}
Json.net can be downloaded from http://www.newtonsoft.com/products/json/