7

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": ''
}
1
  • ryudice, ever find a solution to this? Commented Jan 11, 2012 at 0:18

1 Answer 1

2

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
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.