SuperObject cannot handle empty string

Some JSON serializers return null for an empty string data field, for example.

 { "searchtext": null, "moretext": "contains something", "bookdate": 1377468000000, "empid": 12345, "listtype": 1 } 

I use SuperObject to create an ISuperObject:

 var FJSONRequest: ISuperObject; then FJSONRequest := SO(Request.Content); // Webservice request 

Returns an object with a string containing the text 'null' .

Obviously, this is because SuperObject does not care about quotes ( "searchtext": a gives the same results as "searchtext": "a" ).

Before diving into the 980 line tokenizer routine, does anyone have a solution?

I think along the lines (either / or):

  • leave a blank data field from a JSON object

  • returns an empty string

If all else fails, I can still do

 FJSONRequest := SO(StringReplace(Request.Content,': null,',':,',[rfReplaceAll])); 

because I need to process requests coming from the application from one of our developers, but this is not perfect.
(No, he cannot suppress null , because there is an error in the way that Mono processes his datacontract .)

BTW I experience exactly the behavior mentioned here , but in a different part of the SuperObject code, so the workaround does not work.

+3
source share
1 answer

The official ZIP 1.2.4 file in the http://code.google.com/p/superobject/downloads/list download section dates from 2010, but the individual files in http://code.google.com/p/superobject/source/ browse updated to October 2012

If you go to this last URL and click Download zip , you can get them.

These updated files allow you to use the special case of null .

The code still "forgives" if you omit the quotation marks around the string value:

 { "bookdate": 1377554400000, "searchtext": a, "listtype": 1 } 

but now he is handling a special case

 { "bookdate": 1377554400000, "searchtext": null, "listtype": 1 } 

as if it were

 { "bookdate": 1377554400000, "searchtext": , "listtype": 1 } 

or

 { "bookdate": 1377554400000, "listtype": 1 } 

[Do not accidentally enter nil or null ]

This version supports up to version VER230 (Delphi XE2) [Note that the “official” 1.2.4 did not even compile on later versions of Delphi], so for later versions of Delphi you will have to correct the compiler directives.

It also captures the following:

  • When the floating point value has an exact integer value, JSON will have a wait period:

    {"floatingpointvalue": 4.}

    This is now fixed:

    {"floatingpointvalue": 4}

  • Errors in the conversion of date and time occurring around the switch to switch to daylight saving time in jumps - yes, it is unclear.
    An error occurred in the code section surrounded by {$IFDEF WINDOWSNT_COMPATIBILITY}

Note that this is still defined by default, I suggest you disable the definition, for example. with {.$IFDEF WINDOWSNT_COMPATIBILITY} [who needs to work on Windows NT at present?], which allows the OS to handle date and time conversions:

 {$ELSE} function TzSpecificLocalTimeToSystemTime( lpTimeZoneInformation: PTimeZoneInformation; lpLocalTime, lpUniversalTime: PSystemTime): BOOL; stdcall; external 'kernel32.dll'; function SystemTimeToTzSpecificLocalTime( lpTimeZoneInformation: PTimeZoneInformation; lpUniversalTime, lpLocalTime: PSystemTime): BOOL; stdcall; external 'kernel32.dll'; {$ENDIF} 
+3
source

Source: https://habr.com/ru/post/1499621/


All Articles