1. John Strano
  2. PowerBuilder
  3. Wednesday, 18 January 2023 14:55 PM UTC

Attempting to achieve in the JSON output, the following specification...

"streetLines": [
"PLACEHLDR_SHIPPER_ADDRESS_LINE_1",
"PLACEHLDR_SHIPPER_ADDRESS_LINE_2"
],

Trying...


ljp_address.setvalue( "streetLines", "[ 'PLACEHLDR_SHIPPER_ADDRESS_LINE_1' , 'PLACEHLDR_SHIPPER_ADDRESS_LINE_2 ]" , false )

...of course the service to which this request will be submitted will not tolerate enclosing quotation marks...

"streetLines":"[ 'PLACEHLDR_SHIPPER_ADDRESS_LINE_1' , 'PLACEHLDR_SHIPPER_ADDRESS_LINE_2' ]"

...and of course, the Powerscript compiler will not tolerate the arg list for SetValue() that has an array...

ljp_address.setvalue( "streetLines", ls_my_array_of_street_lines , false )

I dunno...is there something like...
ljp_address.setvalue( "streetLines:1"...
ljp_address.setvalue( "streetLines:2"...

...and eventually, can we get as granular as being able to set the nth element of an array in JSON?


Please advise.
Thank you.

Accepted Answer
Andreas Mykonios Accepted Answer Pending Moderation
  1. Wednesday, 18 January 2023 15:59 PM UTC
  2. PowerBuilder
  3. # Permalink

And the following:

long ll_root, ll_child
JSONGenerator lnv_generator
JSONPackage lnv_jsonpackager

lnv_generator = create JSONGenerator

ll_root = lnv_generator.createjsonarray( )
lnv_generator.AddItemString(ll_root, "PLACEHLDR_SHIPPER_ADDRESS_LINE_1")
lnv_generator.AddItemString(ll_root, "PLACEHLDR_SHIPPER_ADDRESS_LINE_2")

string ls_json_string = '{}'
lnv_jsonpackager = create JSONPackage

lnv_jsonpackager.loadstring(ls_json_string)
lnv_jsonpackager.setvalue("streetLines", lnv_generator.GetJsonString ( ))

lnv_jsonpackager.savetofile("c:\tests\1.json")

if isvalid(lnv_generator) then destroy lnv_generator
if isvalid(lnv_jsonpackager) then destroy lnv_jsonpackager

will have this result:

{
	"streetLines": [
		"PLACEHLDR_SHIPPER_ADDRESS_LINE_1",
		"PLACEHLDR_SHIPPER_ADDRESS_LINE_2"
	]
}

I did format the result with notepad++ to check it.

Andreas.

Comment
There are no comments made yet.
Andreas Mykonios Accepted Answer Pending Moderation
  1. Wednesday, 18 January 2023 15:47 PM UTC
  2. PowerBuilder
  3. # 1

Hi.

You can create your array using jsongenerator.

long ll_root, ll_child
JSONGenerator lnv_generator

lnv_generator = create JSONGenerator

ll_root = lnv_generator.createjsonobject( )
ll_child = lnv_generator.additemarray(ll_root, "streetLines")
lnv_generator.AddItemString(ll_child, "PLACEHLDR_SHIPPER_ADDRESS_LINE_1")
lnv_generator.AddItemString(ll_child, "PLACEHLDR_SHIPPER_ADDRESS_LINE_2")

messagebox("", lnv_generator.GetJsonString ( ))

if isvalid(lnv_generator) then destroy lnv_generator

Don't know if you can do the same using jsonpackage.

Andreas.

Comment
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.