Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Connection Type

LoadString – PB Docs 2022 – PowerBuilder Library

LoadString – PB Docs 2022

LoadString

PowerScript function

Description

Loads a JSON string to the JSONParser or JSONPackage objects.

Applies to

JSONParser and JSONPackage

Required JSON format

  • For JSONParser object: The string that can be loaded by the
    JSONParser object must be JSON-formatted.

  • For JSONPackage object: The string that can be loaded by the
    JSONPackage object must be an object which contains a set of key/value
    pairs where key is the name of a JSONObjectItem-type object
    (corresponding to the data being added into the package, such as
    “d_department” and “d_employee_syntax”) and the value for the key can
    be a string, object, or array in the following formats: plain JSON, or
    DataWindow JSON.

    Here is the structure of this JSON format:

    Here is an example of this JSON format:

    If the root of the JSON string is an array (not an object), as
    shown below, it is NOT supported by JSONPackage (but supported by
    JSONParser):

    You can change the JSON string like below, so it can be
    supported by JSONPackage:

    or

Note

To make sure your JSON file or JSON string is in the standard JSON
format, you can use any third-party tool (such as the online JSON tool)
to validate the JSON format.

Syntax

Argument

Description

objectname

The name of the JSONParser or JSONPackage object to which
the JSON string will be loaded.

JsonData

(For JSONParser object) A JSON-formatted string.

(For JSONPackage object) The JSON data of JsonObjectItem
type.

Return value

String.

Returns the empty string (“”) if it succeeds and the error message
if an error occurs. If any argument’s value is null, the method returns
null.

Usage

If a string is already loaded by this function, calling this
function again will clean up the original string and then load the new
string.

After the JSON string is loaded, you can get the data through the
following methods:

  • gets an array according to its item path. See below Example
    3.

  • gets the JSON string of an array according to its item handle.
    See below Example 4.

  • gets the item handle from a JSONParser object according to the
    item path from a two-dimensional array. See below Example 5.

  • gets the total number of child items according to the parent
    item handle and then gets the value of every array item in a loop. See
    below Example 6.

  • determines the type of number values according to the item
    handle. See below Example 7.

  • handles an irregular JSON string which contains a null value.
    See below Example 8.

Examples

Example 1: This example loads a JSON string into the JSONParser
object.

Example 2: This example gets the data from the server and then loads
the “d_employee” data to the DataWindow.

Example 3: The following code gets an array according to its item
path.

Example 4: The following code gets the JSON string of an array
according to its item handle.

Example 5: This example gets the item handle from a JSONParser
object according to the item path from a two-dimensional array. The number
indicates the order of the array.

Example 6: This example gets the total number of child items
according to the parent item handle and then gets the value of every array
item in a loop.

Example 7: This example determines the type of number values
according to the item handle.

Example 8: The following code handles an irregular JSON string which
contains a null value.

See also

LoadFile


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x