You are not logged in.
Pages: 1
Hi,
a quiet simple call to UrlEncodeJsonObject will fail in an exception (Delphi 10.3.3).
Sample project:
program Project2;
{$APPTYPE CONSOLE}
{$R *.res}
uses
SynCommons,
System.SysUtils;
procedure Test;
var
SendDataJSON, SendDataEncoded: RawUTF8;
begin
SendDataJSON := '{"b":30,"a":12}';
SendDataEncoded := UrlEncodeJsonObject('', PUTF8Char(SendDataJSON), []);
Writeln(SendDataEncoded);
end;
begin
try
Test;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
Offline
The problem is that the JSON input is modified in place: it needs to be copied before parsing in your case, since SendDatAJSON is a read-only string.
If you write @SendDataJSON[1] it should make a copy and let the test pass - at least with Delphi.
I have made it explicit in the doc, and written an overloaded function which makes the copy.
See https://synopse.info/fossil/info/668368aeba
Offline
Pages: 1