You are not logged in.
Pages: 1
i test JSONToObject function ,it works , but seems to change the json content.
i want to reuse the json content ,
follow the Documentation's guide ,
i make a local copy use @vJson[1] or UniqueRawUTF8
but after JSONToObject ,i write the vJson variable content to a memo , it only contains "classname"
var
vJson:rawutf8;
vJsonP:PUTF8Char;
begin
vJsonP :=UniqueRawUTF8(vJson);//@vJson[1];
vObj :=TMyObject(JSONToNewObject(vJsonP,vObjValid,[j2oIgnoreUnknownProperty]));
memo1.text:=vJson; //<--here it only output "classname" not the whole json content
end;
seems local copy did not work
Offline
It is as expected.
When you call UniqueRawUtf8() your vJson variable will become unique, and JsonToNewObject() will parse it in-place.
Your local copy is parsed in-place, so modified.
This is as documented.
But if you make a copy of vJson before, this copy won't be escaped.
To make a copy with no memory allocation for small content, use a local TSynTempBuffer instance.
There are plenty of samples of TSynTempBuffer use in mORMot.pas.
Offline
thanks for the quick reply .
so , if i DONT need to reuse the json, there is no need to call UniqueRawUtf8,
just
vObj :=TMyObject(JSONToNewObject(Pointor(vJson),vObjValid,[j2oIgnoreUnknownProperty]));
will be ok ? am i right?
Offline
Pages: 1