util.JSONObject.name() returns the name of the name:value pair by its index.
Syntax:
util.JSONObject.name(pair_index)
Parameters:
pair_index |
an index of the element of the specified JSON object (= the name:value pair ) |
Usage and examples:
util.JSONObject.name() takes the pair index in the specified JSON object as the parameter and returns the name.
The index of the first name:value pair is 1.
If the JSON object included no pair with the specified name, the method returns NULL.
example code |
MAIN DEFINE json_obj util.JSONObject LET json_obj = util.JSONObject.parse('{"id":123,"name":"Scott","surname":"Smith"}') DISPLAY json_obj.name(1) DISPLAY json_obj.name(2) DISPLAY json_obj.name(3) CALL fgl_getkey() END MAIN
|
obtained results |
|
This method can be used together with util.JSONObject.getLength() and util.JSONObject.getType() in order to read the elements of JSON objects:
MAIN DEFINE json_obj util.JSONObject DEFINE i INTEGER
LET json_obj = util.JSONObject.parse('{"id":12,"name":"Scott, Frank", "address":"5 Brando Str."}')
FOR i = 1 TO json_obj.getLength() DISPLAY i, ": ", json_obj.name(i), "=", json_obj.get(json_obj.name(i)) END FOR CALL fgl_getkey() END MAIN
|
|
obtained results #2 |
|
Example programs:
CVS server: client.querix.com
CVS repository: /lycia_doc_examples
User: client
Project: auxiliary_features/json
Program: util_JSONObject_name
Related articles: