Sets a member within a JSON object or element within a JSON array to the given array of values. New in 2.1.1

Syntax

Result = SRP_Json(Handle, "SetValueArray", Identifier, Array, Delim)

Returns

Returns 1 if successful, 0 if not.

Parameters

ParameterDescription
HandleHandle to a JSON Entity. Required.
ArrayArray of values to be put into the JSON entity. Required.
DelimThe array's delimiter. Optional.

Remarks

The SetValueArray service sets a child within a given JSON Entity. This service only works on JSON objects and JSON arrays. If it is a JSON object, then Identifier needs to be a member name, such as "id" or "first-name". If it is a JSON array, then identifier needs to be an index, such as 1 or 10. Normally, to set an array at at given location, you have to create the array first and load all its values, like this:

ValueArray = "1,2,3,4"
If SRP_Json(ArrayHandle, "New", "Array") then
    For each Value in ValueArray using ","
        SRP_Json(ArrayHandle, "AddValue", Value)
    Next Value
    SRP_Json(ObjectHandle, "Set", "my-array", ArrayHandle)
    SRP_Json(ArrayHandle, "Release")
end

This service does that work for you, simplifying the above code to this:

SRP_Json(ObjectHandle, "SetValueArray", "my-array", "1,2,3,4", ",")

Delim indicates the delimiter used to separate values in Array, which defaults to @FM if omitted.The Delim parameter indicates the delimiter used to separate values in Array, which defaults to @FM if omitted.

Example

// Create a JSON object and add an array as one of the members
If SRP_Json(ObjectHandle, "New", "Object") then
   SRP_Json(ObjectHandle, "SetValueArray", "phone", "(555) 555-1234":@FM:"(555) 555-9876")
   SRP_Json(ObjectHandle, "SetValueArray", "contacts", "Joe,Bob,Kevin", ",")
   SRP_Json(ObjectHandle, "Release")
end

See Also

SetValue

  • No labels