util.JSONObject.getType() returns the type of the element of the specified JSON object.
Syntax:
util.JSONObject.getType("element_name")
Parameters:
|
element_name |
a name of the element of the specified JSON object (= the name:value pair ) |
Possible values:
|
NUMBER |
for numeric values |
|
STRING |
for string values |
|
BOOLEAN |
for boolean values |
|
OBJECT |
for structured objects |
|
ARRAY |
for ordered lists of elements |
|
NULL |
if there is no such element in the specified JSON object |
Usage and examples:
util.JSONObject.get() takes the name of the element of the specified JSON object (= the name:value pair ) as the parameter and returns the type of this element.
|
example code #1 |
MAIN DEFINE json_obj util.JSONObject LET json_obj = util.JSONObject.create() CALL json_obj.put("id", 8723) CALL json_obj.put("name", "Brando")
DISPLAY json_obj.getType("id") DISPLAY json_obj.getType("name") DISPLAY json_obj.getType("address") CALL fgl_getkey() END MAIN
|
|
obtained results #1 |
|
This method can be used together with util.JSONObject.name() 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)), ": ", json_obj.getType("name") 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_getType
Related articles: