1. Yiannis Papadomichelakis
  2. PowerBuilder
  3. Tuesday, 9 June 2020 17:07 PM UTC

I am studding the JSON support in PowerBuilder 2019 (R2) and I am a bit confused on how can I obtain the JSON string of a key in an array.

Let's suppose that you have the following JSON:

{
"Sales":[
{
"DiscountType":{
"Id":1,
"Label":"667 trig",
"CatalogList":[
{
"Id":1,
"Label":"01/01/2000 - 31/12/2099"
}
]
}
},
{
"DiscountType":{
"Id":2,
"Label":"777 777",
"CatalogList":[
{
"Id":2,
"Label":"01/01/2000 - 31/12/2099"
}
]
}
}
]
}

How am I supposed to get the second DiscountType as a JSON string?

As far as I understand, JsonParser can not give you JSON blocks. JSONPackage.GetValue() returns a  JSON block, however, in my example, I can't tell it to give me the second DiscountType.

So... what am I missing here?

 

 

 

Armeen Mazda @Appeon Accepted Answer Pending Moderation
  1. Monday, 11 January 2021 16:55 PM UTC
  2. PowerBuilder
  3. # 1

Hi Yiannis, 

The JSON Parser & Generator has been greatly enhanced in PowerBuilder 2019 R3.  I think the enhancement we did should make it very easy to accomplish what you want to do.  Here is more information about the JSON enhancements: https://docs.appeon.com/pb2019r3/whats_new/ch01s10.html

Best regards,
Armeen

Comment
There are no comments made yet.
Govinda Lopez @Appeon Accepted Answer Pending Moderation
  1. Monday, 11 January 2021 16:46 PM UTC
  2. PowerBuilder
  3. # 2

Hi Yiannis,

 

You might want to try out the GetItemType() method of the JSONParser object (https://docs.appeon.com/pb2019r2/powerscript_reference/ch10s278.html)

 

With it you'll notice that you can obtain the type of object inside of the JSON string:

 

Return value

JsonItemType.

Returns the JsonItemType enumerated value if it succeeds and null value if an error occurs. If any argument's value is null, the method returns null.

The JsonItemType enumerated values are:

  • JsonStringItem! -- Type of the JSON node whose key value pair is a string, such as "name":"evan".

  • JsonNumberItem! -- Type of the JSON node whose key value pair is a number, such as "id":1001.

  • JsonBooleanItem! -- Type of the JSON node whose key value pair is a boolean, such as "active":true.

  • JsonNullItem! -- Type of the JSON node whose key value pair is null, such as "remark": null.

  • JsonObjectItem! -- Type of the JSON node whose key value pair is an object, such as "date_object":{"datetime":7234930293, "date": "2017-09-21", "time": "12:00:00"}.

  • JsonArrayItem! -- Type of the JSON node whose key value pair is an array, such as "department_array":[999999, {"name":"Website"}, {"name":"PowerBuilder"}, {"name":"IT"}].

 

Some simple examples are included in that document too.

 

Regards,

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