You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Creates a new JSON Entity.

Syntax

Result = SRP_JSON(Handle, "NEW", Type, NewValue)

Returns

Returns 1 if successful, 0 if not.

Parameters

ParameterDescription
Handle [OUT]Variable to receive new handle to a JSON Entity. Required.
TypeThe new entity's type: Array, Object, String, Number, or Boolean. Optional.
NewValueThe new entity's value. Optional.

Remarks

The NEW service creates a new JSON entity. A JSON entity can be an object, array, string, number, boolean, or null. The type of entity created is determined by the Type parameter, which you can set to "OBJECT", "ARRAY", "STRING", "NUMBER", "BOOLEAN", or "NULL". The NewValue parameter is also optional, but it provides a convenient way to initialize strings, numbers, and booleans. The parameter does nothing for arrays and objects due to their inherent complexity.

If you leave the Type parameter blank (or omit it altogether), then the type is automatically determined from the contents of NewValue. If NewValue is omitted completely, then "OBJECT" is the type. If NewValue is included but empty, then "NULL" is assumed. If NewValue contains a number, then "NUMBER" is the type. In all other cases, the type defaults to "STRING".

This method's return value is not a JSON Entity Handle; it is a boolean indicating the success or failure of this service. The JSON Entity Handle is instead placed into the variable you pass into the Handle parameter. It is perfectly safe to set Handle to an unassigned variable, but you should check the return value to see if the entity was successfully created, like so:

 

If SRP_JSON(NewObjectHandle, "NEW") then
   // Success, the handle now points to a new JSON object
end else
   // Failure, NewObjectHandle is not valid
end

IMPORTANT: Any JSON entity created by this service must be deallocated from memory when no longer needed using the RELEASE service. Forgetting to do this on occasion will not cause a fatal error since SRP Utilities will clean up all its memory when OpenInsight closes, but frequently failing to release entities causes memory to get used up, which can become a problem over long periods of time.

Example

// Let's create some entities.
Success = SRP_JSON(ObjectHandle, "NEW", "OBJECT")
Success = SRP_JSON(IntegerHandle, "NEW", "NUMBER", "1234567890")
Success = SRP_JSON(DecimalHandle, "NEW", "NUMBER", "123456789.987654321")
Success = SRP_JSON(StringHandle, "NEW", "STRING", "Hello, World!")
Success = SRP_JSON(BooleanHandle, "NEW", "BOOLEAN", 1)
Success = SRP_JSON(ArrayHandle, "NEW", "ARRAY")

// Don't forget to release them when we're done
SRP_JSON(ArrayHandle, "RELEASE")
SRP_JSON(BooleanHandle, "RELEASE")
SRP_JSON(StringHandle, "RELEASE")
SRP_JSON(DecimalHandle, "RELEASE")
SRP_JSON(IntegerHandle, "RELEASE")
SRP_JSON(ObjectHandle, "RELEASE")

See Also

PARSERELEASE

  • No labels