You are not logged in.
Pages: 1
Hello,
I'm getting an Access violation when calling JsonToObject.
Exception raise at Unit SynCommons, at function GetJSONField(P: PUTF8Char; out PDest: PUTF8Char; wasString: PBoolean=nil; EndOfObject: PUTF8Char=nil): PUTF8Char;
Line 43205 : D^ := P^; // 3 stages pipelined process of unescaped chars
Code is really basic :
TCRMUser = class(TPersistent)
private
FAdmin: Boolean;
FFdId: Double;
FId: Double;
FName: RawUTF8;
FSocietes: TArray<RawUTF8>;
FUser: RawUTF8;
// public
published
property admin: Boolean read FAdmin write FAdmin;
property fdId: Double read FFdId write FFdId;
property id: Double read FId write FId;
property name: RawUTF8 read FName write FName;
property societes: TArray<RawUTF8> read FSocietes write FSocietes;
property User: RawUTF8 read FUser write FUser;
end;
var
CRMUser: TCRMUser;
JSON: RawUTF8;
IsValidJson: Boolean;
begin
TJSONSerializer.RegisterClassForJSON([TCRMUser]);
CRMUser := TCRMUser.Create;
try
JSON := '{"admin":false,"fdId":37,"id":17,"name":"Jean-Pierre LeGros","societes":["DODO","DROUAULT"],"User":"jplegros"}';
JSONToObject(CRMUser, PUTF8Char(JSON), IsValidJson);
with Memo1 do
begin
clear;
Lines.Add(CRMUser.User);
end;
finally
CRMUser.Free;
end;
end;
Last edited by swierzbicki (2016-01-28 10:50:57)
Offline
@mpv : doesn't helps.
Offline
Declaring JSON outside the procedure solved the problem. Is this expected ?
Offline
I'm working with the trunk version (did a GIT clone this morning).
I'm using Delphi XE 10 Seattle Update 1. Issue on both x32 and x64
Offline
The JSON is a constant, so is stored directly in the executable.
JSONToObject() is doing in-place parsing (to avoid memory allocation), so it WRITES its input buffer.
Since the input buffer is JSON, it is a read-only memory place.
So the Access Violation.
Just force the creation of an intermediate copy:
JSONToObject(CRMUser, @JSON[1], IsValidJson);
Offline
Pages: 1