Newtonsoft.Json序列化和反序列
来源:互联网 发布:怎样清除淘宝缓存 编辑:程序博客网 时间:2024/04/29 19:44
这里下载:http://www.newtonsoft.com/products/json/
安装:
1.解压下载文件,得到Newtonsoft.Json.dll
2.在项目中添加引用..
序列化和反序列在.net项目中:
读取JSON
结果显示:
TokenType ValueType Value StartArraynullnullStringSystem.StringJSON!IntegerSystem.Int321BooleanSystem.BooleanTrueStartObjectnullnullPropertyNameSystem.StringpropertyStringSystem.StringvalueEndObjectnullnullEndArraynullnull
这里会打印出:
安装:
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 = JsonConvert.SerializeObject(product);
//{
// "Name": "Apple",
// "Expiry": new Date(1230422400000),
// "Price": 3.99,
// "Sizes": [
// "Small",
// "Medium",
// "Large"
// ]
//}
Product deserializedProduct = JsonConvert.DeserializeObject<Product>(output);
读取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序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- Newtonsoft.Json序列化和反序列
- newTonSoft.Json进行序列化和反序列化
- Newtonsoft.Json的序列化和反序列化
- Newtonsoft.Json 序列化和反序列化
- ASP.NET:使用Newtonsoft.Json序列化和反序列化JSON对象的例子
- 利用Newtonsoft.Json序列化,反序列化,读取,写入
- Newtonsoft.Json.dll 中的序列化与反序列化
- Launching Your iPhone App Via Custom URL Scheme
- asp.net Development Server单机版的IIS
- PAT, PMT in MPEG2 Stream :筆記
- linux kernel 常用函数 备忘
- Tab选项卡通用js功能函数(留着以后用)
- Newtonsoft.Json序列化和反序列
- Struts2 官方教程之Struts Tags(七)——Generic Tags(Data Tags )
- 与C++特性相关的面试题
- linux之间建立信任关系
- 工行卡如何自助查询开户行
- 说说PHP的autoLoad
- DateTimePicker 日期的格式化
- HTML5 canvas画圆角框
- C/C++代码的log通过logcat输出