2013-05-09 97 views
2

我JSON陣列,通過採用序列Newtonsoft列表如下刪除Null值

[{"ID":"1","Name":"somename","Class":"12","Section":null},{"ID":null,"Name":"somename","Class":"13","Section":null},{"ID":2,"Name":"somename","Class":null,"Section":"A"}] 

一個字符串,我需要通過刪除NULL值到另一個JSONString像下面

這個JSON轉換
[{"ID":"1","Name":"somename","Class":"12",},{"Name":"somename","Class":"13",},{"ID":2,"Name":"somename","Section":"A"}] 

有沒有一種方法可以使用牛頓軟件,或者我該如何操作。

回答

9

您可以使用JsonSerializerSettingsNullValueHandling

var result = JsonConvert.SerializeObject(obj, 
      new JsonSerializerSettings() 
      { 
       NullValueHandling = NullValueHandling.Ignore 
      }); 
+2

要命的Cuong。謝謝 :) – user2067567 2013-05-09 06:46:03