Some JSON serializers return null
for an empty string datafield, e.g.
{
"searchtext": null,
"moretext": "contains something",
"bookdate": 1377468000000,
"empid": 12345,
"listtype": 1
}
I'm using SuperObject to create a ISuperObject:
var
FJSONRequest: ISuperObject;
then
FJSONRequest := SO(Request.Content); // Webservice request
This returns an object with a string containing the text 'null'
.
Obviously this is because SuperObject does not care about the quotes ("searchtext": a
gives the same results as "searchtext": "a"
).
Before I dive into the 980-line tokenizer routine, does any one have a solution?
I'm thinking along the lines (either/or):
leave the null datafield out of the JSON object
return an empty string
If all else fails I could still do
FJSONRequest := SO(StringReplace(Request.Content,': null,',':,',[rfReplaceAll]));
because I only need to handle requests coming from an app from one of our developers, but that's not foolproof.
(No, he cannot suppress the null
because there's a bug in the way Mono handles his datacontract.)
BTW I'm experiencing exactly the behaviour mentioned here, but in another part of the SuperObject code, so that workaround does not do the job.