使用NewtonSoft.JSON.dll来序列化和发序列化对象
来源:互联网 发布:linux怎么添修改用户id 编辑:程序博客网 时间:2024/05/19 21:42
从这里下载: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'}]
.
- 使用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序列化和反序列
- 使用ROW_NUMBER 删除重复数据
- Lesson 05: Working with Disconnected Data - The DataSet and SqlDataAdapter(使用断开数据--DataSet和SqlDataAdapter)
- 敬邀您参加9月20日ITProCity同城聚会,活动主题Exchange灾难复原
- Lesson 06: Adding Parameters to Commands(向命令中添加参数)
- [转]VC的若干实用小技巧
- 使用NewtonSoft.JSON.dll来序列化和发序列化对象
- Lesson 07: Using Stored Procedures(使用存储过程)
- MFC教程(12)-- 对话框和对话框类CDialog(2)
- emacs操作文件
- ADO.NET 的最佳实践技巧
- Struts-Logic 标签库
- CSS总结
- 查询某字符字段内容最大最小长度
- webservice定义及调用