Delphi/SuperObject-访问子节点 [英] Delphi / SuperObject - Accessing Subnodes

查看:489
本文介绍了Delphi/SuperObject-访问子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从服务器获取以下JSON:

I have the following JSON from my server:

{
   "userid":"12",
   "username":"TestChar",
   "logged":"yes",
   "status":"Premium User",
   "areas":{
      "SERVICEAREA_XX1":{
         "id":"1",
         "area":"SERVICEAREA_XX1",
         "version":"3000",
         "usr_group":"0"
      },
      "SERVICEAREA_XX2":{
         "id":"2",
         "area":"SERVICEAREA_XX2",
         "version":"31000",
         "usr_group":"0"
      },
      "SERVICEAREA_XX3":{
         "id":"3",
         "area":"SERVICEAREA_XX3",
         "version":"2000",
         "usr_group":"1"
      }
   }
}

使用SuperObjects,我可以通过以下方式获得"SERVICEAREA"的计数:

With SuperObjects i can get the count of "SERVICEAREA"'s with

ob['areas'].AsObject.count

我现在如何访问不同的"SERVICEAREA"元素?

How can i now get access to the elements of the different "SERVICEAREA"'s?

感谢您的帮助...

推荐答案

Marjan为您提供了答案.下面是一个示例,提供了更多有关如何访问项目属性的信息:

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;

这篇关于Delphi/SuperObject-访问子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆