thanks
]]> Values: array[0..2] of TValuePUTF8Char;
since you need 3 parameters.
(switching from a dynamic array to a static array enhance performance and stability, since the heap is not used)
Note that if your V.JSON is a RawUTF8, you could write:
Values[2].ToUTF8(V.JSON);
which is slightly better.
Or even, to be more consistent:
V.ID := Values[0].ToInteger;
V.TimeStamp := Values[1].ToCardinal;
Values[2].ToUTF8(V.JSON);
I am using a customreader function (D2007) to convert a JSON string to a record based on the example reference on;
http://blog.synopse.info/post/2013/12/1 … ialization
namely the example;
class function TTestServiceOrientedArchitecture.CustomReader(P: PUTF8Char;
var aValue; out aValid: Boolean): PUTF8Char;
var V: TSQLRestCacheEntryValue absolute aValue;
Values: TPUtf8CharDynArray;
begin
result := JSONDecode(P,['ID','TimeStamp','JSON'],Values);
if result=nil then
aValid := false else begin
V.ID := GetInteger(Values[0]);
V.TimeStamp := GetCardinal(Values[1]);
V.JSON := Values[2];
aValid := true;
end;
end;
but am trying to update my mORMot library and JSONDecode no longer accepts a TPUtf8CharDynArray (possibly changed to TValuePUTF8CharArray) but am struggling to work out what this should look like instead.
Thanks in advance
Chris
]]>I did not know MQL syntax.
http://wiki.freebase.com/wiki/Mql
But it is pretty interresting, and we may implement something similar to our remote ORM (in addition to the standard SQL "where" clause).
There was an issue when clearing the record content at re-loading from JSON.
I have added a corresponding regression test.
Should be fixed now.
See http://synopse.info/fossil/info/6e28c20745
Thanks for your feedback.
]]>I modified SynSelfTests so the lines above are run twice consecutively and it gives an AV
]]>So it will work only once, unless you make a private copy of the string.
]]>This can be seen if you repeat lines 4035 - 4041 in SynSelfTests.pas more than once (copied below)
Thanks in advance for your help
U := '{"transactions":[{"TRTYPE":"INCOME","TRDATE":"2013-12-09 02:30:04","TRAA":"1.23",'+
'"TRCAT1":{"TITYPE":"C1","TIID":"1","TICID":"","TIDSC30":"description1","TIORDER":"0","TIDEL":"false"},'+
'"TRCAT2":{"TITYPE":"C2","TIID":"2","TICID":"","TIDSC30":"description2","TIORDER":"0","TIDEL":"false"},'+
'"TRCAT3":{"TITYPE":"C3","TIID":"3","TICID":"","TIDSC30":"description3","TIORDER":"0","TIDEL":"false"},'+
'"TRRMK":"Remark",'+
'"TRACID":{"TITYPE":"AC","TIID":"4","TICID":"","TIDSC30":"account1","TIORDER":"0","TIDEL":"false"}}]}';
RecordLoadJSON(Trans,@U[1],TypeInfo(TTestCustomJSON2));
See my answer above.
]]>I just downloaded the nightly build yesterday before doing my tests. SynCommons.pas is dated Nov 29, 2013.
This is the full JSON that I need to serialize:
JSONOut:='{"result":{"ok":"true","message":"","syncTime":"2013-12-12T20:55:47.000000"},
"transactions":['+
'{"TRTYPE":"INCOME","TRDATE":"2013-12-12 20:45:20","TRAA":"1.23","TRCAT1":"1","TRCAT2":"2","TRCAT3":"3","TRRMK":"Remark","TRACID":"4"},'+
'{"TRTYPE":"EXPENSE","TRDATE":"2013-12-12 20:45:20","TRAA":"1.23","TRCAT1":"1","TRCAT2":null,"TRCAT3":null,"TRRMK":"Remark","TRACID":"5"}'+
']}';
I tried everything I could find in the demos/forum: JSONToObject and LoadFromJSON. Nothing worked so far.
And my java/php developer will not bend any further. :-)
Can you advise what should I use? Records or Objects?
Appreciate your help!
]]>This has already been fixed.
]]>You are right - JSON with nested records is received from non-Mormot server. My server side is developed with Java->hibernate->php.
I tried to use TTextWriter.RegisterCustomJSONSerializerFromText as you suggested.
It threw me an error when the parser came across the nested object. This one: "ESynException.Create('V1,V2,..V16')".
Unit SynCommons.pas
...
procedure TJSONCustomParserFromTextDefinition.Parse
begin
...
case P^ of
',': if PropsMax=cardinal(high(Props)) then
raise ESynException.Create('V1,V2,..V16') else begin
inc(P);
inc(PropsMax);
continue;
end;
':': inc(P);
end;
...
Still I was able to convince my java/php developer to get rid of these trees and just send flat JSON.
So I am good. :-)
Now TTextWriter.RegisterCustomJSONSerializerFromText() supports JSON serialization/unserialization of TGUID values (encoded as JSON strings).
See http://synopse.info/fossil/info/767c34eae7