[fpc-pascal] TJSONParser crash

Michael Van Canneyt michael at freepascal.org
Wed Sep 28 17:32:10 CEST 2022



On Wed, 28 Sep 2022, Hairy Pixels via fpc-pascal wrote:

> Ok I narrowed down this bug I get with 3.2.2 to TJSONParser. 
>
> I’m so confused as to what changed.  FormatJSON prints the JSON as expected but AsString crashes and gives the error I was seeing from the RPC which it trapped as an exception. When it’s send across the RPC layer it must call AsString and then blow up thus giving me this error.
>
> The JSON in question printed from FormatJSON is valid and can be opened in a JSON editor even so I know it’s ok.
>
> ===========================
>
> Request := TJSONParser.Create(Content, DefaultOptions).Parse;
>
> writeln(Request.FormatJSON);  // this prints the JSON correctly (Request ClassName is TJSONObject)
>
> writeln(Request.AsString); 
>
> gives this error:
>
> An unhandled exception occurred at $00000001050261A7:
> EJSON: Cannot convert data from object value

Of course, as AsString will not work on a TJSONObject. 
AsString will only work on the simple types, not on the object or array types or null.

Michael.


More information about the fpc-pascal mailing list