Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 11.1   11.2   11.3   11.4   11.5   12.0   12.1   12.2   12.3   12.4    Statistic    FMM    Blog  

JSON.CreateArrayRef

Creates empty array reference.

Component Version macOS Windows Linux Server iOS SDK
JSON 6.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "JSON.CreateArrayRef" )

Parameters

none

Result

Returns reference number or error.

Description

Creates empty array reference.
Please use JSON.Release later to free the json object.
You can pass the reference number to all MBS JSON functions instead of JSON text.

Examples

Test array reference functions:

# create array reference
$ref = MBS( "JSON.CreateArrayRef" )
# add some numbers
$r = MBS( "JSON.AddNumberToArray"; $ref; 1; 2; 3 )
# add some texts
$r = MBS( "JSON.AddStringToArray"; $ref; "Hello"; "World" )
# get JSON text for this array:
$text = MBS( "JSON.Compact"; $ref)
# free memory
$r = MBS( "JSON.Release"; $ref )

Use While loop to create JSON array:

Let ( [
    // Create array object
    j = MBS( "JSON.CreateArrayRef" );
    // make a loop to add numbers
    r = While ( $i = 0 ; $i < 10 ; [ r = MBS( "JSON.AddNumberToArray"; j; $i ); $i = $i + 1 ] ; $i );
    // format the result
    text = MBS( "JSON.Format"; j );
    // free json
    r = MBS( "JSON.Release"; j )
];
// return result as text
  text )

Example result: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Create complex JSON:

Set Variable [ $a ; Value: MBS( "JSON.CreateArrayRef" ) ]
#
# first entry
Set Variable [ $o ; Value: MBS( "JSON.CreateObjectRef" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddNumberToObject"; $o; "FieldType"; 11 ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddNullToObject"; $o; "FieldName" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddStringToObject"; $o; "Value"; "Julien" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddBooleanToObject"; $o; "EmptyMatch"; False ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddItemToArray"; $a; $o) ]
Set Variable [ $r ; Value: MBS( "JSON.Release"; $o) ]
#
# second entry
Set Variable [ $o ; Value: MBS( "JSON.CreateObjectRef" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddNumberToObject"; $o; "FieldType"; 23 ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddNullToObject"; $o; "FieldName" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddStringToObject"; $o; "Value"; "Stadel" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddBooleanToObject"; $o; "EmptyMatch"; False ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddItemToArray"; $a; $o) ]
Set Variable [ $r ; Value: MBS( "JSON.Release"; $o) ]
#
# surrounding object
Set Variable [ $o ; Value: MBS( "JSON.CreateObjectRef" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddItemToObject"; $o; "Data"; $a) ]
Set Variable [ $r ; Value: MBS( "JSON.AddNumberToObject"; $o; "Id"; 123 ) ]
Set Variable [ $r ; Value: MBS( "JSON.Release"; $a) ]
#
# put in final object
Set Variable [ $j ; Value: MBS( "JSON.CreateObjectRef" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddItemToObject"; $j; "Address"; $o) ]
Set Variable [ $r ; Value: MBS( "JSON.Release"; $o) ]
#
Set Field [ JSON::JSON ; MBS("JSON.Colorize"; MBS("JSON.Format"; $j)) ]
Set Variable [ $r ; Value: MBS( "JSON.Release"; $j) ]

See also

Example Databases

Blog Entries

Created 5th January 2016, last changed 20th November 2019


JSON.CreateArray - JSON.CreateBool

Feedback: Report problem or ask question.


Start Chat