JSONparser

1
0
-1
I hope you can help
I have the following code which works fine for the first level of fields, how do i get the data for the address1 address2 city and postcode
 
// json return string is 
{
  "id": "W2DBZqIkce",
  "status": "active",
  "type": "customer",
  "ref": "",
  "firstname": "Bob",
  "lastname": "Baker", 
"email": "bbaker@myemail",
  "mobile": "012345678",
  "address": {
    "address1": "9 My Address",
    "address2": "Town",
    "city": "London",
    "postcode": "W1 3PA"
  },
  "dateCreated": "2018-02-21 15:02:57"
}
 
// powerbuilder code
 
 
JSONParser json
json = create JSONParser
ls_result = json.loadstring( ls_string )
 
ll_root = json.getrootitem( )
 
ls_id = json.getitemstring( ll_root, "id" )
ls_status = json.getitemstring( ll_root, "status" )
ls_type = json.getitemstring( ll_root, "type" )
ls_ref = json.getitemstring( ll_root, "ref")
ls_firstname = json.getitemstring( ll_root, "firstname")
ls_lastname = json.getitemstring( ll_root, "lastname")
ls_email = json.getitemstring( ll_root, "email")
ls_mobile = json.getitemstring( ll_root, "mobile")
 
thanks in advance as always 
 
Andrew

Question Tags: 

Answers

Tom Jiang answered JSONparser

1
0
-1

You can just add something like this at the end of your code:

long ll_address
string ls_address1, ls_address2

ll_address=json.GetItemObject(ll_root,"address")
ls_address1=json.getItemString(ll_address,"address1")
ls_address2=json.getItemString(ll_address,"address2")

Regards,

Tom Jiang

Andrew Davis's picture

Awesome - worked perfectly