In WebLin.JSON.pas unit, you have the following method:
function TJSONObject.RemovePair(const PairName: string): TJSONPair;
var
o: TJSObject;
begin
Result := nil;
if Assigned(fjo) then
begin
o := fjo;
asm
delete o[PairName];
end;
end;
end;
Why do you test if fjo is assigned if it is not an object, Is a "PairName :string" what I want to remove?
In the same sense, can you make FMembers public or create another form of traversing all pairs of a TObject?
I'm trying to create a method that copies all the members in a new TJSONObject except the one I want to substitute, but I can't traverse the complete list of members.
Do you know some tip to traverse all the pairs of a TJSONObject by his name?
class function TDataMng.RemoveAPair(const JSONObject :TJSONObject; PairName :string): TJSONObject;
var Pair :TJSONPair;
i :Integer;
begin
Result := TJSONObject.Create;
for i := 0 to JSONObject.Count - 1 do begin
Pair := JSONObject.Pairs[i];
if Pair.JsonString.Value <> PairName then begin
Result.AddPair(Pair.JsonString.Value, Pair.JsonValue.Value);
end;
end;
end;
var
jo: TJSONObject;
i: integer;
jp: TJSONPair;
begin
jo := TJSONOBject.Create;
jo.AddPair(TJSONPair.Create('Name','Joe'));
jo.AddPair(TJSONPair.Create('City','Paris'));
for i := 0 to jo.Count - 1 do
begin
jp := jo.Pairs[i];
console.log(jp.JsonString.Value, jp.JsonValue.Value);
end;
jo.Free;
end;