You are not logged in.
Pages: 1
Hi. mormot result : {"a":"[\"2\"]","b":"2"}
TJSONObject result: {"a":"["2"]","b":"2"}
when I remove line V.a := '["2"]' it is ok! After changing a property json changes.
var
V: Variant;
J: TJSONObject;
NewArray: TJSONArray;
ss: string;
begin
ss := '{"a":["1"],"b":"2"}';
V := _Json(ss);
V.a := '["2"]';
ShowMessage(TDocVariantData(V).ToJson);
j := TJSONObject.ParseJSONValue(ss) as TJSONObject;
NewArray := TJSONArray.Create;
NewArray.Add('2');
j.RemovePair('a').Free;
j.AddPair('a', NewArray);
ShowMessage(j.ToJSON);
Last edited by anouri (2024-11-10 09:52:20)
Offline
I found the problem. It seems it was my mistake:
var
NewArray2: Variant;
begin
ss := '{"a":["1"],"b":"2"}';
NewArray2 := _Arr(['2']);
V := _Json(ss);
V.a := NewArray2;
ShowMessage(TDocVariantData(V).ToJson);
or
LDocDict := DocDict(ss);
LDocDict['a'] := NewArray2;
Last edited by anouri (2024-11-10 10:22:20)
Offline
Here is some samples too:
v := _Json('{"a":["1"],"b":"2"}');
v.a.Delete(0);
v.a.Add('02');
v.a._ := '03'; // same as v.a.Add('03');
Offline
Is it possible change value of element 0 of array v.a without deleting and adding again?
Offline
v.a := _Arr(['2']);
//
_safe(v)^.Values[0] := _Arr(['3']);
_safe(v.a)^.Values[0] := '4';
//
DocDictFrom(v).Update('a', _Arr(['5']));
with DocListFrom(v.a) do
U[0] := '6';
{"a":["2"],"b":"2"}
{"a":["3"],"b":"2"}
{"a":["4"],"b":"2"}
{"a":["5"],"b":"2"}
{"a":["6"],"b":"2"}
Last edited by flydev (2024-11-11 21:36:00)
Offline
Thank you so much. Great framework
Offline
Pages: 1