Page History
Determines if a JSON object contains Contains the given member or if a JSON array contains Contains the given index.
Syntax
Code Block |
---|
Result = SRP_JSONJson(Handle, "CONTAINSContains", Identifier) |
Returns
Returns 1 if entity contains 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 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 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 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
Code Block |
---|
// Create a JSON array, add elements to it, and see if it containsContains the given indexes If SRP_JSONJson(ArrayHandle, "NEWNew", "ARRAY") then SRP_JSONJson(ArrayHandle, "ADDVALUEAddValue", "12345") SRP_JSONJson(ArrayHandle, "ADDVALUEAddValue", 67890, "NUMBER") SRP_JSONJson(ArrayHandle, "ADDVALUEAddValue", 1, "BOOLEAN") Contains = SRP_JSONJson(ArrayHandle, "CONTAINSContains", 1) ; // Returns 1 Contains = SRP_JSONJson(ArrayHandle, "CONTAINSContains", 3) ; // Returns 1 Contains = SRP_JSONJson(ArrayHandle, "CONTAINSContains", 5) ; // Returns 0 SRP_JSONJson(ArrayHandle, "RELEASERelease") end // Create a JSON object, add members to it, and see if it containsContains the given members If SRP_JSONJson(ObjectHandle, "NEWNew", "OBJECT") then SRP_JSONJson(ObjectHandle, "SETVALUESetValue", "name", "John Doe") SRP_JSONJson(ObjectHandle, "SETVALUESetValue", "city", "Washington D.C.") Contains = SRP_JSONJson(ObjectHandle, "CONTAINSContains", "name") ; // Returns 1 Contains = SRP_JSONJson(ObjectHandle, "CONTAINSContains", "city") ; // Returns 1 Contains = SRP_JSONJson(ObjectHandle, "CONTAINSContains", "phone") ; // Returns 0 SRP_JSONJson(ObjectHandle, "RELEASERelease") end |