1. Rodrigo Rosa
  2. PowerBuilder
  3. Thursday, 19 December 2019 21:50 PM

Hi,

I need to access the json array, but I can't find a way to do that.

Array:


   "department_array":
      
         "name":"Website",
         "col1":"AAA",
         "col2":"AEI"
      },
      
         "name":"PowerBuilder",
         "col1":"BBB",
         "col2":"ABC"
      },
      
         "name":"IT",
         "col1":"CCC",
         "col2":"CDE"
      }
   ]
}

I'm using JSONParser from the 2017 version of powerbuilder.

String ls_json, ls_result
long ll_root, ll_count, ll_index
JSONParser json
json = CREATE JSONParser

ls_Json = '{"department_array":[{"name":"Website", "col":"AAA", "colA":"AEI"}, {"name":"PowerBuilder", "col":"BBB", "colA":"ABC"}, {"name":"IT", "col":"CCC", "colA":"CDE"}] }'
ls_result = json.LoadString (ls_Json)

ll_root = json.GetRootItem()
ll_count = json.GetChildCount(ll_root)

FOR ll_index = 1 TO ll_count
ls_key = json.getchildkey(ll_child,ll_index)
NEXT

I need get the column name and values to all array and inserting in the datawindow

Thanks
Accepted Answer
Ken Guo @Appeon Accepted Answer Pending Moderation
  1. Friday, 20 December 2019 05:45 AM
  2. PowerBuilder
  3. # Permalink
2
Votes
Undo

Hi Rodrigo

 

Mike’s reply is correct. You need to use the GetItemArray function. You can refer to the following code for details:

 

String ls_json, ls_result, ls_name, ls_col, ls_colA

long i,ll_root, ll_count, ll_index,ll_child,ll_array, ll_row

JSONParser json

json = CREATE JSONParser

 

ls_Json = '{"department_array":[{"name":"Website", "col":"AAA", "colA":"AEI"}, {"name":"PowerBuilder", "col":"BBB", "colA":"ABC"}, {"name":"IT", "col":"CCC", "colA":"CDE"}] }'

ls_result = json.LoadString (ls_Json)

 

ll_root = json.GetRootItem()

ll_array = json.GetItemArray(ll_root, 'department_array')

 

ll_count = json.GetChildCount(ll_array)

For i = 1 to ll_count

                ll_index = json.GetChildItem(ll_array, i)

                ls_name = json.GetItemString(ll_index, "name")

                ls_col = json.GetItemString(ll_index, "col")

                ls_colA = json.GetItemString(ll_index, "colA")

Next

 

 

Regards,

Ken

 

Comment
Thanks, solved my problem
  1. Rodrigo Rosa
  2. Monday, 6 January 2020 22:00 PM
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Thursday, 19 December 2019 22:29 PM
  2. PowerBuilder
  3. # 1
2
Votes
Undo

objectname.GetItemArray ( ParentItemHandle, Key )

Comment


Thanks
  1. Rodrigo Rosa
  2. Monday, 6 January 2020 22:00 PM
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.