1. André Monz
  2. PowerBuilder
  3. Tuesday, 3 September 2019 09:22 AM UTC

Hello,

i'm trying to merge 2 JSON Strings with jasonpackage.setvalue.
Unfortunately the key 'aeao' will be appended not be replaced.
Maybe somebody see what am i doing wrong?

 

JsonPackage ljs_pack
string ls_Json
string ls_aeao
integer li_rc

ls_Json='{"data":{"aeao":{}},"state":"ACTIVE","type":"RECEIPT","client_id":"d64e8056-0cba-43aa-9ba2-e9e563f12166"}'
ls_aeao='{"receipt_type":"RECEIPT"}'

ljs_pack=create JsonPackage
ljs_pack.LoadString( ls_Json)

ljs_pack=create JsonPackage
ljs_pack.LoadString( ls_Json)
li_rc=ljs_pack.setvalue( "aeao",ls_aeao)

/*
Result:
 
{"data":{"aeao":{}},"state":"ACTIVE","type":"RECEIPT","client_id":"d64e8056-0cba-43aa-9ba2-e9e563f12166","aeao":{"receipt_type":"RECEIPT"}}

but i need:

{"data":{"aeao":{"receipt_type":"RECEIPT"}},"state":"ACTIVE","type":"RECEIPT","client_id":"d64e8056-0cba-43aa-9ba2-e9e563f12166"}

*/

 

Accepted Answer
Ken Guo @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 4 September 2019 04:05 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi André

 

You can use the below code to set the data's value directly:

ls_aeao = '{"aeao":{"receipt_type":"RECEIPT"}}'

li_rc=ljs_pack.setvalue( "data",ls_aeao)

 

Or you can use the following code to assemble aeao json first and then set the data's value:

JsonGenerator lnv_JsonGenerator

Long ll_RootObject, ll_ChildObject

 lnv_JsonGenerator = Create JsonGenerator

ll_RootObject = lnv_JsonGenerator.CreateJsonObject ()

ll_ChildObject = lnv_JsonGenerator.AddItemObject(ll_RootObject,'aeao')

lnv_JsonGenerator.AddItemString(ll_ChildObject, "receipt_type", "RECEIPT")

ls_aeao = lnv_JsonGenerator.getjsonstring( )

li_rc=ljs_pack.setvalue( "data",ls_aeao)

 

Regards,

Ken

 

Comment
  1. André Monz
  2. Wednesday, 4 September 2019 11:04 AM UTC
Hello Ken,



thank you very much.

I got i running with your code examples.



Regards,

André

  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 3 September 2019 14:51 PM UTC
  2. PowerBuilder
  3. # 1

Don't know too much about JSON but:

If you do ljs_pack.GetValue("data") you get:

{"aeao":{}}

 

if you do ljs_pack.GetValue("aeao") you get 

nothing !

 

In other words, "aeao" does not really seem to be a key on which you can do a SetValue().

 

 

Comment
  1. André Monz
  2. Wednesday, 4 September 2019 04:03 AM UTC
Ups, my bad, should be just one create and loadstring.

  1. Helpful
  1. André Monz
  2. Wednesday, 4 September 2019 11:06 AM UTC
Hi Miguel,

Thank you for your Comment.

The json-Script i finally want to insert consists of many Arrays.

I'm not sure, replace() will handle such json-Strings correkt.



Regards,

André
  1. Helpful
  1. Miguel Leeuwe
  2. Wednesday, 4 September 2019 14:29 PM UTC
Yw,

I've learned something here :)
  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.