Determines if a JSON object contains the given member or if a JSON array contains the given index.
Syntax
Result = SRP_JSON(Handle, "CONTAINS", Identifier)
Returns
Returns 1 if entity contains the given identifier, 0 if not.
Parameters
Parameter | Description |
---|---|
Handle | Handle to JSON Entity. Required. |
Identifier | The object member or array element to find. Required. |
Remarks
The CONTAINS service determines if the given identifier is found within the JSON entity. This service only works on JSON objects and JSON arrays and will return 0 for entities of type String, Number, and Boolean. If the entity is a JSON object, then the identifier should be a member name. For example, you would pass "FirstName" to see if the JSON object contains a member whose name is "FirstName". If the entity is a JSON array, then identifier should be an element index. For example, you would pass "10" to see if the array contains a tenth element.
NOTE: Object member names are case sensitive. So, passing "MyMemberName" will return 0 if the JSON object has a member whose name is "mymembername". As for arrays, the first element is always at index 1, just like BASIC+ dynamic arrays.
Example
// Create a JSON array, add elements to it, and see if it contains the given indexes If SRP_JSON(ArrayHandle, "NEW", "ARRAY") then SRP_JSON(ArrayHandle, "ADDVALUE", "12345") SRP_JSON(ArrayHandle, "ADDVALUE", 67890, "NUMBER") SRP_JSON(ArrayHandle, "ADDVALUE", 1, "BOOLEAN") Contains = SRP_JSON(ArrayHandle, "CONTAINS", 1) ; // Returns 1 Contains = SRP_JSON(ArrayHandle, "CONTAINS", 3) ; // Returns 1 Contains = SRP_JSON(ArrayHandle, "CONTAINS", 5) ; // Returns 0 SRP_JSON(ArrayHandle, "RELEASE") end // Create a JSON object, add members to it, and see if it contains the given members If SRP_JSON(ObjectHandle, "NEW", "OBJECT") then SRP_JSON(ObjectHandle, "SETVALUE", "name", "John Doe") SRP_JSON(ObjectHandle, "SETVALUE", "city", "Washington D.C.") Contains = SRP_JSON(ObjectHandle, "CONTAINS", "name") ; // Returns 1 Contains = SRP_JSON(ObjectHandle, "CONTAINS", "city") ; // Returns 1 Contains = SRP_JSON(ObjectHandle, "CONTAINS", "phone") ; // Returns 0 SRP_JSON(ObjectHandle, "RELEASE") end