util.JSONObject.getLength()

 

util.JSONObject.getLength() returns the number of the name:value pairs  included in the specified JSON object.

 

Syntax:

 

util.JSONObject.getLength()

 

Usage and examples:

 

util.JSONObject.getLength() is used to return or display how many name:value pairs  there are in the specified JSON object.

 

example code #1

MAIN

  DEFINE json_obj util.JSONObject

    LET json_obj = util.JSONObject.parse('{"id":123,"name":"Scott"}')

    DISPLAY json_obj.getLength()

  CALL fgl_getkey()

END MAIN

 

obtained results #1

 

example code #2

 

MAIN

  DEFINE json_obj util.JSONObject

  DEFINE cust_rec RECORD

             cust_num INTEGER,

             cust_name VARCHAR(30),

             order_id DYNAMIC ARRAY OF INTEGER

         END RECORD

    LET cust_rec.cust_num = 345

    LET cust_rec.cust_name = "McMaclum"

    LET cust_rec.order_id = 4732

    LET json_obj = util.JSONObject.fromFGL(cust_rec)

    DISPLAY json_obj.getLength()

  CALL fgl_getkey()

END MAIN

 

obtained results #2

 

 

This method can be used together with util.JSONObject.name() and util.JSONObject.getType()  in order to read the elements of JSON objects:

 

 

 

 

Example programs:

CVS server: client.querix.com

CVS repository: /lycia_doc_examples

User: client

Project: auxiliary_features/json

Program: util_JSONObject_getLength

 

Related articles:

util.JSONObject.getType()

util.JSONObject.name()