Returns the number of members in a JSON object or elements in a JSON array.
Syntax
Result = SRP_JSON(Handle, "GETCOUNT")
Returns
Returns the number of members in a JSON object or elements in a JSON array.
Parameters
Parameter | Description |
---|---|
Handle | Handle to a JSON Entity. Required. |
Remarks
The GETCOUNT service returns the number of children within the given JSON Entity. If it is a JSON object, then it counts the number of members. If it is a JSON array, then it counts the number of elements. If there are no children, or if the handle points to a String, Number, or Boolean type entity, then the result will be 0.
Example
// Create a JSON array, add elements to it, and get the count If SRP_JSON(ArrayHandle, "NEW", "ARRAY") then SRP_JSON(ArrayHandle, "ADDVALUE", "12345") SRP_JSON(ArrayHandle, "ADDVALUE", 67890, "NUMBER") SRP_JSON(ArrayHandle, "ADDVALUE", 1, "BOOLEAN") Count = SRP_JSON(ArrayHandle, "GETCOUNT") ; // Returns 3 SRP_JSON(ArrayHandle, "RELEASE") end // Create a JSON object, add members to it, and get the count If SRP_JSON(ObjectHandle, "NEW", "OBJECT") then SRP_JSON(ObjectHandle, "SETVALUE", "name", "John Doe") SRP_JSON(ObjectHandle, "SETVALUE", "city", "Washington D.C.") Count = SRP_JSON(ObjectHandle, "GETCOUNT") ; // Returns 2 SRP_JSON(ObjectHandle, "RELEASE") end