1. Ong Chin Keat
  2. PowerBuilder
  3. Tuesday, 11 June 2024 02:26 AM UTC
{
	"submissionUid": "CNWRXZESJEZ1YQC3E7T8G20J10",
	"acceptedDocuments": [
		{
			"uuid": "H2YRP9VQXFB4ZFHDE7T8G20J10",
			"invoiceCodeNumber": "9112450011"
		}
	],
	"rejectedDocuments": []
}

hi all,

I'm calling an API and return above result. However, if using jsonpackage, loadstring and getvalue, it will not get "uuid" and "invoiceCodeNumber" value due to exist of barcket [....]. How can overcome this issue? My script as below :  

 

lnv_pack1 = create jsonpackage
lnv_pack2 = create jsonpackage
			
//Load the JSON string via jsonpackage
lnv_pack1.loadstring(ls_string)     //as return result shown above
			
//Get the JSON string under key=batters
ls_sid = lnv_pack1.getvalue("submissionUid")
ls_value = lnv_pack1.getvalue("acceptedDocuments")
//Load the new JSON string via jsonpackage
lnv_pack2.loadstring( ls_value)
ls_uuid = lnv_pack2.getvalue("uuid")               // cannot get 
ls_inv = lnv_pack2.getvalue("invoiceCodeNumber")   // cannot get 

Please help.

 

thanks,

DevOng

 

Accepted Answer
René Ullrich Accepted Answer Pending Moderation
  1. Tuesday, 11 June 2024 05:50 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi DevOng,

I think your can't do it with JsonPackage object.

The problem is that the json string you get for acceptedDocuments is a json array. You can't directly import it with LoadString because this json string has no root.

 

For parsing Json it is better to use the JsonParser.

Here is a short example:

lnv_parser = create jsonparser

//Load the JSON string via jsonparser
lnv_parser.loadstring(ls_string)
			
//Get handle for the JSON Array for acceptedDocuments
ll_docsarray = lnv_parser.getitemarray("/acceptedDocuments")

//get handle for the first item of Json array
ll_arrayitem = lnv_parser.getchilditem(ll_docsarray, 1)

// get the uuid value from the first item
ls_uuid = lnv_parser.getitemstring(ll_arrayitem, "uuid")

HTH,

René

Comment
  1. Ong Chin Keat
  2. Tuesday, 11 June 2024 10:55 AM UTC
hi Rene,

Noted, it's work. thanks a lot.
  1. Helpful
There are no comments made yet.


There are replies in this question but you are not allowed to view the replies from this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.