I'm using json.net to serialize a class that has strings, however, when it is converted to json the strings are convert to null, is there a way I could make json.net convert null strings to emtpy strings ('') and not null?
Here is what I currently get
var client = {
"FirstName": null,
"LastName": null
}
and I want this:
var client = {
"FirstName": '',
"LastName": ''
}
try:
client.FirstName||''
This will return '' if FirstName
is null. Better still create a helper function like this:
function null2empty(a){
return a||'';//You might want to check for strings only before returning
}
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