I have JSON that I am getting back that potentially gets back nulls as part of the values. How can I, or is there even a way, to exclude those nulls from the collection?
{
"id": "5551212",
"from": {
"name": "Message creator",
"start_time": "2011-10-21T22:00:00",
"end_time": "2011-10-23T17:00:00",
"location": "area 51",
"id": "2121212122"
},
"to": {
"data": [
{
"name": "Jay-Z",
"id": "77777"
},
{
"name": "Bill Murray",
"id": "88888"
},
null,
{
"name": "Anthony Hopkins",
"id": "99999"
}
]
},
"message": "Some message from somewhere",
"updated_time": "2011-09-19T23:53:51+0000",
"unread": 1,
"unseen": 0
}
Notice between Bill Murray and Anthony Hopkins the null that is returned. Thanks.
You can simply decorate properties/fields that can be null with
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string Name { get; set; }
For more info on how to reduce json size: http://james.newtonking.com/archive/2009/10/23/efficient-json-with-json-net-reducing-serialized-json-size.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With