This blog is a knowledge base...where I clip cool tricks and urls

Json.net

use JSON instead XML

Json.NET



09 September 2007
Filed under: ,


The Json.NET library makes working with JavaScript and JSON formatted data in .NET simple. Quickly read and write JSON using the JsonReader and JsonWriter or serialize your .NET objects with a single method call using the JsonSerializer. 

Json.NET CodePlex Project

Json.NET Download



Product product = new Product();

product.Name = "Apple";

product.Expiry = new DateTime(2008, 12, 28);

product.Price = 3.99M;

product.Sizes = new string[] { "Small", "Medium", "Large" };

 

string json = JavaScriptConvert.SerializeObject(product);

//{

//  "Name": "Apple",

//  "Expiry": new Date(1230422400000),

//  "Price": 3.99,

//  "Sizes": [

//    "Small",

//    "Medium",

//    "Large"

//  ]

//}

 

Product deserializedProduct = JavaScriptConvert.DeserializeObject<Product>(json);


 blog it

No comments: