util.JSONObject class

 

util.JSONObject class is used to modify and manipulate structured data objects following the JSON string syntax.

 

JSON object is an unordered collection of name:value pairs. JSON objects are enclosed in braces - { to begin the object and } to end it. Every name is followed by : (colon) and is separated from another one by , (comma):

 

 

{

  "cust_num":2735,

  "cust_name":"McCarlson",

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

  "address": {

          "street":"34, Sunset Bld",

          "city":"Los Angeles",

          "state":"CA"

        }

}

 

JSON objects are created by the util.JSONObject.create() method.

Once created, JSON objects can be studied and manipulated by util.JSONObject methods summarized in the table below.

 

method

description and examples

util.JSONObject.create()

creates a new JSON object

 

util.JSONObject.fromFGL()

 creates a new JSON object from a RECORD

 

util.JSONObject.parse()

parses a JSON string into a new JSON object

 

util.JSONObject.get()

returns a value that corresponds to the specified entry name

 

util.JSONObject.getLength()

returns the number of the name:value pairs  included in the specified JSON object

 

util.JSONObject.getType()

returns the type of the element of the specified JSON object

 

util.JSONObject.has()

checks whether the JSON object includes the element with the specified name

 

util.JSONObject.name()

returns the name of the name:value pair by its index

 

util.JSONObject.put()

adds a name:value pair  to the specified JSON object

 

util.JSONObject.remove()

removes the specified element from the JSON object

 

util.JSONObject.toFGL()

fills a RECORD with the elements of the JSON object

 

util.JSONObject.toString()

produces a JSON string from the values included into the JSON object