Versions Compared

Key

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

[ Image Removed |../../../index.htm#lansa/jsoneng01_0030.htm]
現在地: Webサービス > JSON データの作業 > XPRIM_RandomAccessJsonReader を使用した、JSON 値の読み込み > Read…WithPath メソッド

...

Wiki MarkupRead…WithPath メソッドを使って、パスでによって JSON データ内の位置が指定された値を読み込みます。パスは、スラッシュで区切られた一連のメンバ名、アレイ・インデックスです。

例えば、前回の例にあった以下の JSON 文字列を使うとします。 \{    

{
    "name":

...


      { 
        "given":"John",

...


        "surname":"Smith"

...


    },

...

...

"given" のメンバ値 (John) へのパスは、"name/given".となります。

さらに前回の例から次の JSON 文字列を使用します。 \{    

{
    ...

...


    "contactNo":

...


    [
        { area:"02",

...

no:"9378

...

2867",

...

type:"landline"

...

\},

...


        { no:"0468

...

732

...

371",

...

type:"mobile"

...

\}
    ]

最初の連絡先     \] 最初の連絡先 (contact number) の市外局番 (area) へのパスは "contactNo/1/area" です。

インデックスは常に1 がベースなることに注意してください。これは RDML の基準です。

それでは実際にメソッドを使用してみましょう。

"given" "surname" のメンバ値の取得は以下のようになります。

#GivenName

...

:=

...

#Reader.ReadStringWithPath("name/given")

...


#Surname

...

:=

...

#Reader.ReadStringWithPath("name/surname")

"name" オブジェクトを開いて入ることもできます。こうすれば、パスで "name" のセグメントを繰り返す必要がありません。

#Reader.BeginObjectWithPath("name")

...


#GivenName

...

:=

...

#Reader.ReadStringWithPath("given")

...


#Surname

...

:=

...

#Reader.ReadStringWithPath("surname")

...


#Reader.EndObject

以下のように、最初の連絡先から連絡先のタイプを取得できます。

#ContactNoType

...

:=

...

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

もしくは、最初に "contactNo" の最初のエレメントにナビゲートし、次に "type" の値を取得することもできます。

#Reader.BeginObjectWithPath("contactNo/1")

...


#ContactNoType

...

:=

...

#Reader.ReadStringWithPath("type")

...


#Reader.EndObject

次は:  Read…WithName メソッド 次は: [<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]