Syntax
JSONAddArray <json-var> <member-name> <list-var>Description
Add an array to a JSON object.Parameters
<json-var>
- A variable containing the JSON object to which the array is to be added.
<member-name>
- The name of the member in the JSON object that is to contain the array.
<list-var>
- The list of items that make up the array. The items may be JSON objects or normal PhantomScript values.
Remarks
JSON (JavaScript Object Notation) is a lightweight data format based on the object notation of the JavaScript language. It does not require JavaScript to read or write; it is easy to parse by any language and libraries and tools exist in many languages to handle JSON.Here is the entire list of PhantomScript JSON statements: ListAsJSONArray, JSONAddArray, JSONAddBoolean, JSONAddNull, JSONAddNumber, JSONAddObject, JSONAddString, JSONArrayAsList, JSONGetKeys, JSONGetType, JSONGetValue, JSONDelete.
Example
Local jsonObj1
JSONAddString jsonObj1 "string1" "a string value"
JSONAddNumber jsonObj1 "a-number" 42
JSONAddBoolean jsonObj1 "a-boolean" (1 == 1)
Local jsonObj2
JSONAddString jsonObj2 "string2" "another string value"
JSONAddString jsonObj2 "string3" "yet another string value"
Local alist
AppendItem alist "xx"
AppendItem alist "yy"
AppendItem alist "zz"
AppendItem alist 123
AppendItem alist (1 = 2)
AppendItem alist jsonObj2
JSONAddArray jsonObj1 "my-array" alist
MessageBox Text=jsonObj1The above script fragment displays this JSON object in the message box: ,
{ "string1": "a string value", "a-number": 42, "a-boolean": true, "my-array": [ "xx", "yy", "zz", 123, false, { "string2": "another string value", "string3": "yet another string value" } ] }.