method toJSON

void toJSON(stream stream);

Argumente

Zurückgegebener Wert

This method creates a JSON UTF-8 encoding of the array values. The values in the array are unchanged. The following value types are supported: double, int64, int64, uint32, int32, uint16, int16, uint8, int8, string, time, bool, array, and dictionary. If a time element is encountered, the value is converted to milliseconds and stored as integer. All integers are stored as either a 64 bit or 32 bit signed integer, depending on their size.

When the array contains an element type that is not supported by this method, it returns the EE_INVALID_PARAM error.

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);
jsonStream.close();
/*
The resulting JSON in the stream will look like this:
[
    42,
    "Hello World",
    ["john", "tom",]
    {"brother":["john", "tom"]},
    "false"    
]
*/