Removes all members from a JSON obect or all elements from a JSON array.
Syntax
Result = SRP_JSON(Handle, "REMOVEALL")
Returns
Returns 1 if successful, 0 if not.
Parameters
Parameter | Description |
---|---|
Handle | Handle to a JSON Entity. Required. |
Remarks
The REMOVEALL service removes all children from a 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, all named members are removed. If the entity is a JSON array, then all elements are removed and the array size is 0.
Example
// Create a JSON array If SRP_JSON(ArrayHandle, "NEW", "ARRAY") then // Add elements to it SRP_JSON(ArrayHandle, "ADDVALUE", "12345") SRP_JSON(ArrayHandle, "ADDVALUE", 67890, "NUMBER") SRP_JSON(ArrayHandle, "ADDVALUE", 1, "BOOLEAN") // Get the count, which is currently 3 Count = SRP_JSON(ObjectHandle, "GETCOUNT") // Delete everything and get the count again, which will be 0 Result = SRP_JSON(ArrayHandle, "REMOVEALL") Count = SRP_JSON(ArrayHandle, "GETCOUNT") SRP_JSON(ArrayHandle, "RELEASE") end // Create a JSON object If SRP_JSON(ObjectHandle, "NEW", "OBJECT") then // Add members to it SRP_JSON(ObjectHandle, "SETVALUE", "name", "John Doe") SRP_JSON(ObjectHandle, "SETVALUE", "city", "Washington D.C.") // Get the count, which is currently 2 Count = SRP_JSON(ObjectHandle, "GETCOUNT") // Delete everything and get the count again, which will be 0 Result = SRP_JSON(ObjectHandle, "REMOVEALL") Count = SRP_JSON(ObjectHandle, "GETCOUNT") SRP_JSON(ObjectHandle, "RELEASE") end