1. vignesh ramkumar
  2. PowerBuilder
  3. Wednesday, 7 April 2021 06:14 AM UTC

Hi Gurus,

 

We have migrated the PB from 2017 r3 to 2019 r3. We have a Json string building function which is working fine in 2017 where as its not building the expected array string in 2019. Following is the code

 

Jsongenerator jga

 jga = create JSONGenerator 

 

ll_jsonarray = jga.CreateJsonArray()

 

ll_child = jga.AddItemobject(ll_jsonarray)

jga.AddItemString(ll_child,"paramName", "ai_acct_id")
jga.AddItemnumber(ll_child,"paramvalue", ai_acct_id)
jga.AddItemString(ll_child,"paramName", "ai_acct_owner")
jga.AddItemnumber(ll_child,"paramvalue", ai_acct_owner)
jga.AddItemString(ll_child,"paramName", "ai_cust_id")
jga.AddItemnumber(ll_child,"paramvalue", ai_cust_id)
jga.AddItemString(ll_child,"paramName", "ai_cust_owner")
jga.AddItemnumber(ll_child,"paramvalue", ai_cust_owner)
jga.AddItemString(ll_child,"paramName", "as_branchid")
jga.AddItemnumber(ll_child,"paramvalue", ll_branch_id)
jga.AddItemString(ll_child,"paramName", "as_state")
jga.AddItemString(ll_child,"paramvalue", ls_state)
jga.AddItemString(ll_child,"paramName", "as_country")
jga.AddItemString(ll_child,"paramvalue", ls_country)
jga.AddItemString(ll_child,"paramName", "as_version")
jga.AddItemString(ll_child,"paramvalue", "APP")

 

ls_json1 = jga.getjsonstring( )

 

Expected result string:


[{"paramName":"ai_acct_id","paramvalue":1111,

"paramName":"ai_acct_owner","paramvalue":111,

"paramName":"ai_cust_id","paramvalue":1111,

"paramName":"ai_cust_owner","paramvalue":111,

"paramName":"as_branchid","paramvalue":111,

"paramName":"as_state","paramvalue":"AA",

"paramName":"as_country","paramvalue":"bbb",

"paramName":"as_version","paramvalue":""}]

 

What we got in 2019:

[{"paramName":"as_version","paramvalue":""}]

 

Am i missing anything here?.

 

Thanks

Vignesh

 

Accepted Answer
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 7 April 2021 15:34 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi Vignesh;

  FWIW:  This test code works for me ....


Jsongenerator jga
Long  ll_child
Long  ll_jsonarray
long    ll_handle
String ls_json1

 jga = create JSONGenerator
ll_jsonarray = jga.CreateJsonArray()
ll_child = jga.AddItemobject(ll_jsonarray)
ll_handle = jga.AddItemString(ll_child,"paramName", "ai_acct_id")
ll_handle =jga.AddItemnumber(ll_child,"paramvalue", 1)
ll_child = jga.AddItemobject(ll_jsonarray)
ll_handle =jga.AddItemString(ll_child,"paramName", "ai_acct_owner")
ll_handle =jga.AddItemnumber(ll_child,"paramvalue", 99 )
ll_child = jga.AddItemobject(ll_jsonarray)
ll_handle =jga.AddItemString(ll_child,"paramName", "ai_cust_id")
ll_handle =jga.AddItemnumber(ll_child,"paramvalue", 123 )
ll_child = jga.AddItemobject(ll_jsonarray)
ll_handle =jga.AddItemString(ll_child,"paramName", "ai_cust_owner")
ll_handle =jga.AddItemnumber(ll_child,"paramvalue", 999 )
ll_child = jga.AddItemobject(ll_jsonarray)
ll_handle =jga.AddItemString(ll_child,"paramName", "as_branchid")
ll_handle =jga.AddItemnumber(ll_child,"paramvalue", 321 )
ll_child = jga.AddItemobject(ll_jsonarray)
ll_handle =jga.AddItemString(ll_child,"paramName", "as_state")
ll_handle =jga.AddItemString(ll_child,"paramvalue", "CA" )
ll_child = jga.AddItemobject(ll_jsonarray)
ll_handle =jga.AddItemString(ll_child,"paramName", "as_country")
ll_handle =jga.AddItemString(ll_child,"paramvalue", "USA" )
ll_child = jga.AddItemobject(ll_jsonarray)
ll_handle =jga.AddItemString(ll_child,"paramName", "as_version")
ll_handle =jga.AddItemString(ll_child,"paramvalue", "APP")
ls_json1 = jga.getjsonstring( )


Regards .... Chris

Comment
There are no comments made yet.
vignesh ramkumar Accepted Answer Pending Moderation
  1. Thursday, 8 April 2021 11:57 AM UTC
  2. PowerBuilder
  3. # 1

Hi ken,

 

Thanks for the update.

 

Vignesh

Comment
There are no comments made yet.
Ken Guo @Appeon Accepted Answer Pending Moderation
  1. Thursday, 8 April 2021 08:28 AM UTC
  2. PowerBuilder
  3. # 2

Hi Vignesh,

The code you provided has different execution results in PB 2017 R3/PB 2019 R2 and PB 2019 R3. This is because Appeon has improved it, or in other words, fixed this defect.

The Json generated in PB 2017 R3/PB 2019 R2 contains duplicate keys, which is not reasonable, and they are not array.

This issue has been fixed in PB 2019 R3. So if you want to create array, please refer to Chris’s method to implement it.

Regards,
Ken

Comment
There are no comments made yet.
vignesh ramkumar Accepted Answer Pending Moderation
  1. Thursday, 8 April 2021 03:58 AM UTC
  2. PowerBuilder
  3. # 3

Hi Chirs,

 

Thanks for the code, Yes it does work :)

 

Thanks

Vignesh

Comment
  1. Chris Pollach @Appeon
  2. Thursday, 8 April 2021 16:23 PM UTC
Hi Vignesh;

That is great news .. thanks for the feedback! :-)

Regards ... Chris
  1. Helpful
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.