JSON.NET

这是一个.NET框架使用的 JSON 解析和操作的类库 Json.net


该项目主页:http://www.codeplex.com/Json


引用

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;

示例代码:

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

List<Product> deserializedProduct = JsonConvert.DeserializeObject<List<Product> >(json);

 
 
   
LINQ to JSON Example
string json = @"{
  ""Name"": ""Apple"",
  ""Expiry"": new Date(1230422400000),
  ""Price"": 3.99,
  ""Sizes"": [
    ""Small"",
    ""Medium"",
    ""Large""
  ]
}";
 
JObject o = JObject.Parse(json);
 
string name = (string)o["Name"];
// Apple
 
JArray sizes = (JArray)o["Sizes"];
 
string smallest = (string)sizes[0];
// Small




 
 
 

你可能感兴趣的:(apple,Date,.net,json,String,LINQ)