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

ParameterDescription
HandleHandle to JSON Entity. Required.
IdentifierThe 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

See Also

GetGetCountSet

  • No labels