How to remove null value in json string

Hi I'm using the below class

Public List<string> name;
Public List<string> midname;

Once I serialize it I'm getting the following output like

 {"name":[hari],"midname":null}

But I want my answer to be like this

{"name":[hari]}

It shouldn't display the class attribute that has null value and I'm using c# .net framework.

 

 

If you are using Json.Net then You can try this by Decorating your property like this

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public List<string> name { get; set; }

 

参考地址:http://stackoverflow.com/questions/15574506/how-to-remove-null-value-in-json-string

posted @ 2016-06-29 15:55  屌丝大叔的笔记  阅读(203)  评论(0编辑  收藏  举报