Versions Compared

Key

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

...

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 "OBJECTObject", "ARRAYArray", "STRINGString", "NUMBERNumber", "BOOLEANBoolean", or "NULLNull". 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 "OBJECTObject" is the type. If NewValue is included but empty, then "NULLNull" is assumed. If NewValue contains a number, then "NUMBERNumber" is the type. In all other cases, the type defaults to "STRINGString".

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
// Let's create some entities.
Success = SRP_Json(ObjectHandle, "New", "OBJECTObject")
Success = SRP_Json(IntegerHandle, "New", "NUMBERNumber", "1234567890")
Success = SRP_Json(DecimalHandle, "New", "NUMBERNumber", "123456789.987654321")
Success = SRP_Json(StringHandle, "New", "STRINGString", "Hello, World!")
Success = SRP_Json(BooleanHandle, "New", "BOOLEANBoolean", 1)
Success = SRP_Json(ArrayHandle, "New", "ARRAYArray")

// 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")

...