2
我有一類這樣的:C#JSON.Net NullValueHandling的列表<object>
public class media
{
public string id { get; set; }
public string code { get; set; }
public string url { get; set; }
public string comment_count { get; set; }
public string like_count { get; set; }
public int no { get; set; }
}
我創建一個列表
List<media> my_stack = new List<media>();
我說在我的列表中的某些媒體;
media new_media = new media();
new_media.id = "some id";
new_media.code = "value";
new_media.url = "value";
my_stack.Add(new_media);
new_media = new media();
new_media.id = "some id";
new_media.url = "value";
my_stack.Add(new_media);
new_media = new media();
new_media.id = "some id";
new_media.url = "value";
new_media.code = "value";
new_media.comment_count = "value";
new_media.like_count = "value";
my_stack.Add(new_media);
當我SerializeObject List<media> media
結果是全空的屬性。
[
{"id":"some id", "code":"value", "url":"value","comment_count":null, "like_count": null, "no":0},
{"id":"some id", "code":null, "url":"value","comment_count":null, "like_count": null, "no":0},
{"id":"some id", "code":"value", "url":"value","comment_count":"value", "like_count": "value", "no":0}
]
我不想null值。 我嘗試了兩件關於NullValueHandling但不適合我的工作。
1:How to ignore a property in class if null, using json.net
我覺得NullValueHandling不工作List<object>
序列化?
我如何刪除我的List json中的空值?
謝謝。這對我有用。 –