0

Im receiving quirky issues with my json data from my asp.net MVC WebApi coming into my kendoUI controls because null strings are being sent across as

"FielName":null

Im wondering how do I go about setting up the jsonformatter on my webapi so that string fields with a null value return empty string "" instead of Null like? So looks like.

"FieldName":""

Thanks

j0k
  • 22,600
  • 28
  • 79
  • 90
Matt
  • 3,305
  • 11
  • 54
  • 98
  • This is answered in this previous question - http://stackoverflow.com/questions/6507889/how-to-ignore-a-property-in-class-if-it-is-null-using-json-net – Paige Cook Aug 17 '12 at 01:17
  • @PaigeCook That post seems to talk about ignoring null properties. I dont want to ignore them, I want to convert properties of type System.String to "" if they are null?? – Matt Aug 17 '12 at 01:29

1 Answers1

1

You can look to modify the JsonFormatter and change it's ContractResolver to be something a little different. This question: Serializing null in JSON.NET looks like it could be easily adapted for your purposes (just by updating the default JsonFormatter).

Community
  • 1
  • 1
Chris
  • 772
  • 3
  • 8