You are not logged in.
Pages: 1
Hello,
Is there a way in mORMot to parse a json like below?
["9af5fdb57d837c02","9af5fdb57dc8e575","9af5fdb57d4fdb61"]
When I check in online tools it resolves as a valid json.
Thanks & regards,
Ertan
Offline
Below code did parse above json nicely.
var
ParsedValues: TStringDynArray;
begin
if DynArrayLoadJSON(ParsedValues, Pointer(Json), TypeInfo(TStringDynArray)) <> nil then ShowMessage('Parse OK');
end;
Offline
Now, I have another challenge with json handling. I just had following json string. That is actually part of a bigger structure.
"v6AssignMode": {
"6plane": false,
"rfc4193": false,
"zt": false
}
This is last part of that bigger structure and I just stop when I saw that "6plane". My knowledge it is not possible to use a variable name starting with a number. I have to serialize and de-serialize that structure.
I wonder if there is a better solution other than using a StringReplace() and hope not to break anything else in that json?
Thanks & regards,
Ertan
Offline
Offline
I tried below using Delphi 10.3.1 and all is good. Both serialization and de-serialization works.
type
TTest = packed record
plane: Boolean;
rfc4193: Boolean;
zt: Boolean;
end;
TMyType = packed record
v6AssignMode: TTest;
end;
const
__TMyType = 'v6AssignMode{ 6plane boolean rfc4193 boolean zt boolean}';
procedure TForm1.Button1Click(Sender: TObject);
var
Target: string;
Json: string;
TestType1: TMyType;
TestType2: TMyType;
begin
TestType1.v6AssignMode.plane := True;
TestType1.v6AssignMode.rfc4193 := False;
TestType1.v6AssignMode.zt := True;
Json := RecordSaveJSON(TestType1, TypeInfo(TMyType));
ShowMessage('Generated: ' + string(Json)); // Here I read JSON with "6plane" in it.
Target := '{"v6AssignMode":{"6plane":false,"rfc4193":false,"zt":false}}';
if RecordLoadJSON(TestType2, RawUTF8(Target), TypeInfo(TMyType)) then ShowMessage('OK') else ShowMessage('NOK'); // Here a json string with "6plane" in it correctly de-serialized
end;
Thank you.
Offline
You could also write 'v6AssignMode{ 6plane,rfc4193,zt:boolean}' for the definition.
That's good to know. It is better for me to shorten as much as possible since main json structure is a big one.
Thanks.
Offline
Pages: 1