Resolved JsonGenerator doubt
- How-to
- Pepe Cuenca
- PowerBuilder
- Friday, 4 September 2020 08:32 AM UTC
Hello Everyone!
I'm trying to generate a JSON with JsonGenerator and I think I am missing something.
I generate the Root and insert some fields without problem.
Then I need to create an array Item including some more fields, using additemArray
It create the array, but nothing is inside.
If I use AddItemObject, it does everyting, but square brackets are missing, and I need them:
Here is my code:
//Declarations
lnv_JsonGenerator = create jsonGenerator
ll_RootObject = lnv_JsonGenerator.CreateJsonObject()
//Inserting data into the JSON
lnv_JsonGenerator.AddItemString(ll_RootObject, "SerieRecepcion", 'M20')
lnv_JsonGenerator.AddItemNumber(ll_RootObject, "NumeroRecepcion", 2)
lnv_JsonGenerator.AddItemString(ll_RootObject, "SeriePartida", 'M20')
lnv_JsonGenerator.AddItemNumber(ll_RootObject, "NumeroPartida", 2)
lnv_JsonGenerator.AddItemString(ll_RootObject, "Fecha","2020-08-14T00:00:00")
lnv_JsonGenerator.AddItemString(ll_RootObject, "CodigoProveedor", '40000000002')
lnv_JsonGenerator.AddItemString(ll_RootObject, "CodigoAsociacion", '')
lnv_JsonGenerator.AddItemString(ll_RootObject, "CodigoArticulo", '10100100')
lnv_JsonGenerator.AddItemString(ll_RootObject, "CodigoCultivo", '')
lnv_JsonGenerator.AddItemString(ll_RootObject, "SerieContrato", 'CONTC')
lnv_JsonGenerator.AddItemNumber(ll_RootObject, "NumeroContrato", 12)
lnv_JsonGenerator.AddItemString(ll_RootObject, "Referencia", 'REF1222')
//Creating the array
ll_ChildArray = lnv_JsonGenerator.AddItemArray(ll_RootObject, "Pesadas")
//Inserting data into the array
lnv_JsonGenerator.AddItemString(ll_ChildArray, "CodigoPalet", '50')
lnv_JsonGenerator.AddItemString(ll_ChildArray, "CodigoEnvase", '100')
lnv_JsonGenerator.AddItemNumber(ll_ChildArray, "CantidadPalets", 1)
lnv_JsonGenerator.AddItemNumber(ll_ChildArray, "CantidadEnvases", 50)
lnv_JsonGenerator.AddItemNumber(ll_ChildArray, "PesoBruto", 500000)
lnv_JsonGenerator.AddItemNumber(ll_ChildArray, "PesoNeto", 361000)
**** EDIT : IF I DO THIS , IT INSERTS THE DATA, BUT OBVIOUSLY NO TAGS, AND I NEED THEM...
lnv_JsonGenerator.AddItemString(ll_ChildArray, '50')
lnv_JsonGenerator.AddItemString(ll_ChildArray, '100')
lnv_JsonGenerator.AddItemNumber(ll_ChildArray, 1)
lnv_JsonGenerator.AddItemNumber(ll_ChildArray, 50)
lnv_JsonGenerator.AddItemNumber(ll_ChildArray, 500000)
lnv_JsonGenerator.AddItemNumber(ll_ChildArray, 361000)
//Getting the string
ls_json = lnv_JsonGenerator.getjsonstring( )
Can anyone tell me what am I missing? I think I understand it, but I cleary don't...
Thank you very much!!
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.