This method populates the array from a JSON
UTF-8 encoding such as what was returned from
toJSON.
The JSON string must start with "[" and end with "]". All values are removed from the array first.
var arrayObj = shell.serviceManager.basics.array;
arrayObj.addValue(42);
arrayObj.addValue("Hello World");
var users = shell.serviceManager.basics.array;
var keyPair = shell.serviceManager.basics.dictionary;
users.addValue("john");
users.addValue("tom");
keyPair.setValueForKey(users, "brother");
arrayObj.addValue(users);
arrayObj.addValue(keyPair);
arrayObj.addValue(false);
var jsonStream = shell.serviceManager.basics.memoryStream;
arrayObj.toJSON(jsonStream);
/*
The resulting JSON in the stream will look like this:
[
42,
"Hello World",
["john", "tom",]
{"brother":["john", "tom"]},
"false"
]
*/
var arrayObj2 = shell.serviceManager.basics.array;
arrayObj2.fromJSON(jsonStream);
jsonStream.close();
/*fromJSON will remove all the elements first
The resulting arrayObj2 will look like this:
42
"Hello World"
Basics::array Object
"john"
"tom"
Basics::dictionary Object
"brother" Basics::array Object
"john"
"tom"
"false"
*/