NewtonSoft.Json

//把Json字符串反序列化为对象
目标对象 = JavaScriptConvert.DeserializeObject(JSON字符串, typeof(目标对象));

//把目标对象序列化为Json字符串

string Json字符串 = JavaScriptConvert.SerializeObject(目标对象);

 

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 output = JavaScriptConvert.SerializeObject(product);
//{
// "Name": "Apple",
// "Expiry": new Date(1230422400000),
// "Price": 3.99,
// "Sizes": [
// "Small",
// "Medium",
// "Large"
// ]
//}

Product deserializedProduct = (Product)JavaScriptConvert.DeserializeObject(output, typeof(Product));

 

string jsonText = "['JSON!',1,true,{property:'value'}]";

JsonReader reader = new JsonReader(new StringReader(jsonText));

Console.WriteLine("TokenType\t\tValueType\t\tValue");

while (reader.Read())
{
Console.WriteLine(reader.TokenType + "\t\t" + WriteValue(reader.ValueType) + "\t\t" + WriteValue(reader.Value))
}


posted @ 2011-12-24 19:26  YF.G  阅读(614)  评论(0编辑  收藏  举报