Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Syntax

Code Block
Result = SRP_JSONJson(Handle, "NEWNew", 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 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.

...

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:

Code Block
If SRP_JSONJson(NewObjectHandle, "NEWNew") 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 RELEASERelease 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

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

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

See Also

PARSEParseRELEASERelease