JSonGenerator Boolean

COBRASoft

Active Member
Licensed User
Longtime User
Hey,

There is a problem with the JSon generator and booleans. It uses true or false and not 0 and 1. So, the generator places text without quotes as value.

E.g. WCF services can't deal with this syntax. Yes, I can use an int and do the translation myself, but I think the JSon generator must do this and generate correct JSon, being 0 or 1 for booleans.

Greetings,
Sigurd
 

warwound

Expert
Licensed User
Longtime User
JSON is an abbreviation of javascript object notation and javascript does use true and false for boolean values.

Have you seen JSONLint?

Copy this into the validator on that page:

B4X:
{
    "a": false
}

The result is:

Valid JSON

A valid JSON string is a string which a javascript engine can evaluate NOT a string which a non-javascript webservice can parse.

Maybe if the webservice you are using didn't describe the fields as boolean but instead described then as integer types then it'd be more logical?

Martin.
 
Upvote 0

COBRASoft

Active Member
Licensed User
Longtime User
Very strange... Integer doesn't help, WCF REST Services expect 0 or 1 for a boolean. Which seems more logical than true and false written in text to me :).

Nevertheless, thanks for the explanation. It would be handy if the developer could specify how booleans are 'translated' into JSon.
 
Upvote 0
Top