Adds a value to a JSON array.

Syntax

Result = SRP_Json(Handle, "AddValue", NewValue, Type)

Returns

Returns 1 if successful, 0 if not.

Parameters

ParameterDescription
HandleHandle to JSON Entity. Required.
NewValueNew value to be added to the JSON array. Required.
TypeThe value's type: String, Number, or Boolean. Optional.

Remarks

The AddValue service adds the given value (String, Number, Boolean, or Null) to the end of the array. This only works if Handle is a JSON array. Unlike the Add service, you do not pass a handle to another JSON entity. This method is also more convenient and a little faster than Add. When you pass the value without specifying its type, then its type is automatically determined from the value itself. Empty values become Null types and values detected to be a number become the Number type. Everything else becomes a string. You can always force the type you want by setting the Type parameter explicitly.

Example

 // Create a JSON array (which initializes ArrayHandle)
If SRP_Json(ArrayHandle, "New", "Array") then

   // This will be added as a String (even though the value contains only numbers)
   SRP_Json(ArrayHandle, "AddValue", "12345")

   // Now add an actual number value to the array
   SRP_Json(ArrayHandle, "AddValue", 67890, "Number")

   // Add a boolean
   SRP_Json(ArrayHandle, "AddValue", 1, "Boolean")

   // Remember to release entities you've created
   SRP_Json(ArrayHandle, "Release")

 end

See Also

Add

  • No labels