栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

SuperObject-全部提取

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SuperObject-全部提取

如果您不知道从某处接收到的JSON的结构,请务必注意JSON是“简单”的复合模式,您可以像其他任何复合结构一样遍历它。以下示例以JSON文本形式遍历完整结构,并打印任何名为“
id”的成员的路径。

procedure ParseJSON;var  JSONText: string;  JSON: ISuperObject;begin  // Retrieve JSON as a string into JSonText variable any way you like.  JSON := SO(JSONText);  ProcessObject(JSON.AsObject);end;procedure ProcessObject(const aAsObject: TSuperTableString; const aPrefix: string = '');var  Names: ISuperObject;  Name: string;  Items: ISuperObject;  Item: ISuperObject;  idx: Integer;  Value: string;  ArrayItem: ISuperObject;begin  if Assigned(aAsObject) then  begin    Names := aAsObject.GetNames;    Items := aAsObject.GetValues;    for idx := 0 to Items.AsArray.Length - 1 do    begin      Name := Names.AsArray[idx].AsString;      Item := Items.AsArray[idx];      if Item.DataType = stObject then        Value := '<Object>'      else if Item.DataType = stArray then        Value := '<Array>'      else        Value := Item.AsString;      if SameText(Name, 'id') then        WriteLn(Format('%s: %s', [aPrefix + Name, Value]));      if Item.DataType = stArray then        for ArrayItem in Item do          ProcessObject(ArrayItem.AsObject, aPrefix + Name + '.');      if Item.DataType = stObject then        ProcessObject(Item.AsObject, aPrefix + Name + '.');    end;  end;end;


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/449317.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号