Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

[ Image Removed |../../index.htm#lansa/jsoneng01_0030.htm]
You are here:

...

Wiki MarkupYou use the Read…WithPath methods to read a value whose location in the JSON data is specified by a path. A path is a sequence of member name and array index, separated by a forward slash.

For example, using the previous JSON string example: \

{

...

   

...

"name":

...


   

...

{

...

       

...

"given":

...

"John",

...

       

...

"surname":

...

"Smith"

...

   

...

},

...

.

...

.

...

.

The path to the "given" member value (John) is "name/given".

And still using the JSON string from the previous example: \

{

...

   

...

.

...

.

...

.

...

   

...

"contactNo":

...

   

...

[

...

       

...

{

...

area:

...

"02",

...

no:

...

"9378

...

2867",

...

type:

...

"landline"

...

},

...

       

...

{

...

no:

...

"0468

...

732

...

371",

...

type:

...

"mobile"

...

}

...

   

...

]

The path to the area code of the first contact number is "contactNo/1/area".

Note that indexes are always 1-based, which is a standard in RDML.

Let's now put it into practice.

We want to get the value of the "given" and "surname" members:

#GivenName

...

:=

...

#Reader.ReadStringWithPath("name/given")

...

#Surname

...

:=

...

#Reader.ReadStringWithPath("name/surname")

We can also open and enter the "name" object so we don't have to repeat the "name" segment in the path:

#Reader.BeginObjectWithPath("name")

...

#GivenName

...

:=

...

#Reader.ReadStringWithPath("given")

...

#Surname

...

:=

...

#Reader.ReadStringWithPath("surname")

...

#Reader.EndObject

To get the contact number type of the first contact number:

#ContactNoType

...

:=

...

#Reader.ReadStringWithPath("contactNo/1/type")

Or you can navigate into the first element of "contactNo" first, then get the "type" value:

#Reader.BeginObjectWithPath("contactNo/1")

...

#ContactNoType

...

:=

...

#Reader.ReadStringWithPath("type")

...

#Reader.EndObject

Next: Read…WithName Next: [<span style="color: #0000ee"><span style="text-decoration: underline; ">Read…WithName</span></span>|jsoneng01_0035.htm] [ !worddavaf485e25f57cd86bb5b0fc63f3f1b1cc.png|height=32,width=32! |../../index.htm#lansa/jsoneng01_0030.htm]