当前位置: 首页 > 工具软件 > SuperObject > 使用案例 >

superobject 遍历

杜经艺
2023-12-01

 最近在处理贯标的JSON数据,为了全部遍历所有的数据。

使用SuperObject.


{
type
  BllParam = record
    sParamName: string;
    sParanAlias: string;
    sParamvalue: string;
    sparsmvalueAlias: string;
    sNode: string;
    iParamType: TFieldType; //
  end;

  arrayBllParam = array of BllParam;
}

function TGBiao.pAnalysisOutput_array(var aprs: arrayBllParam; aOstr: string; aRoot: string): arrayBllParam;
var
  jo, iTEMjo: ISuperObject;
  N: Integer;
begin
  jo := SO(aOstr);
  for N := 0 to jo.AsArray.Length - 1 do
  begin
    jo.AsArray.O[N];
    pAnalysisOutput(aprs,jo.AsArray.O[N].AsString,aRoot);
  end;
end;

function TGBiao.pAnalysisOutput(var aprs: arrayBllParam; aOstr: string; aRoot: string): arrayBllParam;
var
  jo: ISuperObject;
  item: TSuperObjectIter;
begin
  jo := SO(aOstr);
  if ObjectFindFirst(jo, item) then
    repeat
      if item.val.IsType(stObject) then
        pAnalysisOutput(aprs, item.val.AsString, item.key)
      else if item.val.IsType(stArray) then
        pAnalysisOutput_array(aprs, item.val.AsString, item.key)
      else
      begin
//        WriteLog(FMemo, Format('key: %s; val: %s', [item.key, item.val.AsString]));
        GBCODEConver(aprs, aRoot, item.key, item.val.AsString, item.key); --将数据保存到aprs中。
      end;
    until not ObjectFindNext(item);
  ObjectFindClose(item);
end;

 类似资料: