好几次想取json的节点名称,今天搞定了。
procedure GetJsonNames(o: ISuperObject; Strs: TStrings); var ite: TSuperAvlIterator; obj: TSuperAvlEntry; begin ite := TSuperAvlIterator.Create(o.AsObject); try ite.First; obj := ite.GetIter; while obj <> nil do begin strs.Add(obj.Name); ite.Next; obj := ite.GetIter; end; finally ite.Free; end; end; procedure TForm5.Button12Click(Sender: TObject); var o: ISuperObject; Strs: TStrings; begin Strs := TStringList.Create; o := so(‘{"item1":1,"item2":2,"item3":3}‘); GetJsonNames(o, Strs); ShowMessage(Strs.Text); FreeAndNil(Strs); end;
时间: 2024-10-27 18:01:02