util.JSONObject.get

Returns the value corresponding to the specified entry name.

Syntax

util.JSONObject.get(
   name STRING )
  RETURNS result-type
  1. name is the string identifying the JSON object property.
  2. result-type can be a simple type, a util.JSONObject or a util.JSONArray object reference.

Usage

The get() method returns the value or JSON object corresponding to the element name passed as parameter.

If the element identified by the name is a simple value, the method returns a string. If the element is structured, the method returns a util.JSONObject instance and the returned object must be assigned to a program variable defined with the util.JSONObject type. If the element is a list of values, the method a util.JSONArray instance and the returned object must be assigned to a program variable defined with the util.JSONArray type.

A name/value pair can be set with the put() method.

Example

IMPORT util
MAIN
    DEFINE obj, sub util.JSONObject
    DEFINE jarr util.JSONArray
    DEFINE rec RECORD
               id INTEGER,
               name STRING
           END RECORD
    DEFINE arr DYNAMIC ARRAY OF INTEGER
    DEFINE x INT
    LET obj = util.JSONObject.create()
    -- Simple value
    CALL obj.put("simple", 234)
    LET x = obj.get("simple")
    -- Sub-element
    LET rec.id = 234
    LET rec.name = "Barton"
    CALL obj.put("record", rec)
    LET sub = obj.get("record")
    -- Array
    LET arr[1] = 234
    LET arr[2] = 2837
    CALL obj.put("array", arr)
    LET jarr = obj.get("array")
END MAIN