Creates a new JSON Entity.
Syntax
Result = SRP_Json(Handle, "New", Type, NewValue, Delim)
Returns
Returns 1 if successful, 0 if not.
Parameters
Parameter | Description |
---|---|
Handle [OUT] | Variable to receive new handle to a JSON Entity. Required. |
Type | The new entity's type: Array, Object, String, Number, or Boolean. Optional. |
NewValue | The new entity's value. Optional. |
Delim | The NewValue's delimiter. Optional. New in 2.1.1. |
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 anything except objects, due to their inherent complexity.
VERSION NOTE: The ability to initialize arrays was added in version 2.1.1 and is not available prior to that. The Delim parameter allows initializing from any delimited array. If omitted, Delim defaults to @FM.
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", "1,2,3,4,5", ",") // 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")