﻿# 好用的 Json.NET 3.0 已發佈

在這 Web 2.0 的時代，[JSON](http://www.json.org/) 這個資料傳輸格式已經越來越多人在使用了，今年 5 月份 Json.NET 才剛[發佈 2.0 版](https://james.newtonking.com/archive/2008/05/04/json-net-2-0-released/)，在前幾天(8/25)又[發佈 3.0 版](https://james.newtonking.com/archive/2008/08/25/json-net-3-0-released/)，這個新版本除了修正許多所有已知的 Bugs 之外，還添加了許多新功能與特性，其中包括：

-   支援 Silverlight  
      
    大家都知道在 Silverlight 2.0 可以在前端(Browser)執行 .NET 程式，因為 Sliverlight 2.0 內建一個小型的 CLR 與部分 .NET BCL，而 Json.NET 提供一個 Newtonsoft.Json.Silverlight.dll  組件，可供 Silverlight 專案加入參考使用。  
      
    
-   LINQ to JSON 更容易使用  
      
    JObject 類別實做 IDictionary<TKey, TValue>，且 JArray 類別實做 IList<T>，以後要用這些類別就跟用其他 List 或 dictionary 一樣了。  
      
    
-   序列化(Serializer)增強  
      
    最主要有新增 JsonConverterAttribute 屬性，可以資料在被序列化成 JSON 格式時，指定特定的資料表現格式，如下範例：

```
public class Person
{
    // "John Smith"  
    public string Name { get; set; }

    // "2000-12-15T22:11:03"  
    [JsonConverter(typeof(IsoDateTimeConverter))]
    public DateTime BirthDate { get; set; }

    // new Date(976918263055)  
    [JsonConverter(typeof(JavaScriptDateTimeConverter))]
    public DateTime LastModified { get; set; }
}
```

以下是 3.0 版完整的變更清單：

-   New feature - Silverlight Json.NET build.
-   New feature - JObject now implements IDictionary, JArray now implements IList.
-   New feature - Added JsonConverterAttribute. Used to define a JsonConverter to serialize a class or member. Can be placed on classes or fields and properties.
-   New feature - Added DateTimeFormat to IsoDateTimeConverter to customize date format.
-   New feature - Added WriteValue(object) overload to JsonWriter.
-   New feature - Added JTokenEqualityComparer.
-   New feature - Added IJEnumerable. JEnumerable and JToken now both implement IJEnumerable.
-   New feature - Added AsJEnumerable extension method.
-   Change - JsonSerializer does a case insensitive compare when matching property names and constructor params.
-   Change - JObject properties must have a unique name.
-   Bug fix - Internal string buffer properly resizes when parsing long JSON documents.
-   Bug fix - JsonWriter no longer errors in certain conditions when writing a JsonReader's position.
-   Bug fix - JsonSerializer skips multi-token properties when putting together constructor values.
-   Bug fix - Change IConvertible conversions to use ToXXXX methods rather than casting.
-   Bug fix - GetFieldsAndProperties now properly returns a distinct list of member names for classes than have overriden abstract generic properties.

**相關連結**

-   [Json.NET 3.0 Released](https://james.newtonking.com/archive/2008/08/25/json-net-3-0-released/)
-   [好用的 Json.NET 2.0 已發佈](/post/2008/05/19/Json-NET-20-Released)
-   [Introducing JSON](http://json.org/)
-   [JSON](http://zh.wikipedia.org/wiki/JSON "JSON") - Wikipedia
