Delphi / SuperObject - Accessing Subnodes

时光毁灭记忆、已成空白 提交于 2019-12-04 04:37:21

Marjan has the answer for you. Here is a little more information how to access the item properties with an example:

var
  item: ISuperObject;
...
for item in ob['areas'] do
begin
  WriteLn(item['id'].AsInteger);
  WriteLn(item['area'].AsString);
  WriteLn(item['version'].AsInteger);
end;
Marjan Venema

you can access elements of an array using a for ... in loop:

var
  item: ISuperObject;
begin
  for item in ob['areas'] do ...

or without an enumerator, using a 'normal' for loop:

var
  idx: Integer;
  item: ISuperObject;
begin
  for idx := 0 to ob['areas'].AsArray.Length - 1 do
    item := ob['areas'].AsArray[idx];

use this code If you want to access key/value(like Javascriptfor..in)

 if ObjectFindFirst(JsonData, ite) then
    with JsonData.AsObject do
    repeat
      PutO(ite.key, ite.val.Clone);
    until not ObjectFindNext(ite);
    ObjectFindClose(ite);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!