util.JSONObject.parse()

 

util.JSONObject.parse() parses a JSON string into a new JSON object.

 

Syntax:

 

util.JSONObject.parse("source")

 

Parameters:

 

source

a JSON string from which the JSON object is created

 

Usage and examples:

 

util.JSONObject.parse() scans the JSON data string passed as the parameter, separates the pieces of the string that correspond to the structure of a JSON object, and creates a new JSON object.

 

An object newly created by util.JSONObject.parse() must be assigned to a variable of the util.JSONObject data type.

 

example code

MAIN

  DEFINE js STRING

  DEFINE json_obj util.JSONObject

    LET js = '{ "cust_num":273, "cust_name":"McCarlson",

             "orderids":[234,3456,24656,34561],

             "js_obj" : { "js_cust_num":1111, "js_cust_name":"js_McCarlson",

             "js_orderids":[123,2345,34567,45678] } }'

    LET json_obj = util.JSONObject.parse(js)

    DISPLAY json_obj.get("cust_num")

    DISPLAY json_obj.get("cust_name")

    DISPLAY json_obj.get("js_obj").toString()

  CALL fgl_getkey()

END MAIN

 

obtained results

 

If the JSON string is not properly formatted, the -8109 error - Verify the input string passed to the JSON parsing function. See the description for more details - is returned to the user.

 

 

Example programs:

CVS server: client.querix.com

CVS repository: /lycia_doc_examples

User: client

Project: auxiliary_features/json

Program: util_JSONObject_parse

 

Related articles:

util.JSON.parse()