使用NewtonSoft.JSON.dll来序列化和发序列化对象
来源:互联网 发布:剑网3萝莉捏脸 数据图 编辑:程序博客网 时间:2024/05/10 13:45
从这里下载:http://www.newtonsoft.com/products/json/
安装:
1.解压下载文件,得到Newtonsoft.Json.dll
2.在项目中添加引用..
序列化和反序列在.net项目中:
读取JSON
结果显示:
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
这里会打印出:
安装:
1.解压下载文件,得到Newtonsoft.Json.dll
2.在项目中添加引用..
序列化和反序列在.net项目中:
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));
读取JSON
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))
}
结果显示:
JSON写入
StringWriter sw = new StringWriter();
JsonWriter writer = new JsonWriter(sw);
writer.WriteStartArray();
writer.WriteValue("JSON!");
writer.WriteValue(1);
writer.WriteValue(true);
writer.WriteStartObject();
writer.WritePropertyName("property");
writer.WriteValue("value");
writer.WriteEndObject();
writer.WriteEndArray();
writer.Flush();
string jsonText = sw.GetStringBuilder().ToString();
Console.WriteLine(jsonText);
// ['JSON!',1,true,{property:'value'}]
这里会打印出:
['JSON!',1,true,{property:'value'}]
. document.write("");LoadFeedbackCount();
- 使用NewtonSoft.JSON.dll来序列化和发序列化对象
- 使用NewtonSoft.JSON.dll来序列化和发序列化对象
- 使用NewtonSoft.JSON.dll来序列化和发序列化对象
- 使用NewtonSoft.JSON.dll来序列化和发序列化对象
- 使用NewtonSoft.JSON.dll来序列化和发序列化对象
- 使用NewtonSoft.JSON.dll来序列化和反序列化对象
- .Net使用Newtonsoft.Json.dll(JSON.NET)对象序列化成json、反序列化json示例教程
- C# .NET利用Newtonsoft.Json来序列化和反序列化对象
- Newtonsoft.Json.dll使用 .net json序列化与返序列化
- ASP.NET:使用Newtonsoft.Json序列化和反序列化JSON对象的例子
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- NET Framework 类库 OleDbCommand 成员
- .net内存回收与Dispose﹐Close﹐Finalize方法2
- 桌面端的移动运算(一)
- Cache的几种过期使用样例
- 桌面端的移动运算(三)
- 使用NewtonSoft.JSON.dll来序列化和发序列化对象
- css-body背景渐变色的CSS
- 在Microsoft Office System中使用ADO.NET数据集(一)
- AxWMPLib.AxWindowsMediaPlayer按比例伸展
- ASP.NET学习笔记(20080424)----web.config中的session配置详解
- Cache总义Cache用法之页面声明
- 在Microsoft Office System中使用ADO.NET数据集(二)
- VFP9获得Windows虚拟内存(页面值)大小
- Microsoft .Net Remoting系列专题之二:Marshal、Disconnect与生命周期以及跟踪服务