Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi / SuperObject - Accessing Subnodes

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"
      }
   }
}

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

ob['areas'].AsObject.count

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

Thanks for your help...

like image 716
Michael Grenzer Avatar asked Oct 02 '12 03:10

Michael Grenzer


1 Answers

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];
like image 51
Marjan Venema Avatar answered Sep 25 '22 07:09

Marjan Venema