util.JSONObject.has() checks whether the JSON object includes the element with the specified key.
Syntax
CALL util.JSONObject.has("key")
Parameters
key |
a key of the element of the JSON object (= the key:value pair ) |
Usage and examples:
util.JSONObject.has() scans the JSON object for the element (= the key:value pair) with the specified key.
This method returns 1 (= TRUE) if there is such an element in the JSON object and 0 (= FALSE) if it is not.
MAIN
DEFINE json_obj util.JSONObject
LET json_obj=util.JSONObject.create()
CALL json_obj.insert("id",8723)
CALL json_obj.insert("name","Brando")
CALL json_obj.insert("position", NULL)
DISPLAY json_obj.has("name")
CALL fgl_getkey()
END MAIN
MAIN
DEFINE json_obj util.JSONObject
LET json_obj=util.JSONObject.create()CALL json_obj.put("id",8723)
CALL json_obj.insert("name","Brando")
CALL json_obj.insert("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