util.JSONObject.has() checks whether the JSON object includes the element with the specified name.
Syntax:
util.JSONObject.has("element_name")
Parameters:
element_name |
a name of the element of the specified JSON object (= the name:value pair ) |
Usage and examples:
util.JSONObject.has() scans the JSON object for the element (= the name:value pair ) with the specified name and returns 1 (=TRUE) if there is such an element in the JSON object and 0 (=FALSE) if it is not.
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") CALL json_obj.put("position", NULL)
DISPLAY json_obj.has("name")
CALL fgl_getkey() END MAIN
|
obtained results #1 |
|
example code #2 |
MAIN DEFINE json_obj util.JSONObject
LET json_obj = util.JSONObject.create()
CALL json_obj.put("id", 8723) CALL json_obj.put("name", "Brando") CALL json_obj.put("position", "Manager")
IF json_obj.has("id") = TRUE THEN DISPLAY json_obj.get("id") ELSE DISPLAY "No ID property" END IF
IF json_obj.has("name") = TRUE THEN DISPLAY json_obj.get("name") ELSE DISPLAY "No NAME property" END IF
IF json_obj.has("position") = TRUE THEN DISPLAY json_obj.get("position") ELSE DISPLAY "No POSITION property" END IF 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_has