大佬教程收集整理的这篇文章主要介绍了使用NewtonSoft.JSON.dll来序列化和发序列化对象,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Product product = new Product();
product.Name = "Apple";
product.Expiry = new datetiR_267_11845@e(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.@R_675_7548@)
}
TokenType | ValueType | Value |
---|---|---|
StartArray | null | null |
String | System.String | JSON! |
Integer | system.int32 | 1 |
Boolean | System.Boolean | True |
StartObject | null | null |
PropertyName | System.String | property |
String | System.String | value |
EndObject | null | null |
Endarray | null | null |