method toJSON

void toJSON(stream stream);

Argumente

Zurückgegebener Wert

This method creates a JSON UTF-8 encoding of the dictionary pairs. The pairs in the dictionary 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.

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

var dictionary = shell.serviceManager.basics.dictionary;
dictionary.setValueForKey("Hello World", "name");
dictionary.setValueForKey(false, "isVisible");

var users = shell.serviceManager.basics.array;
users.addValue("john");
users.addValue("tom");

dictionary.setValueForKey(users, "users");
dictionary.setValueForKey(400, "width");

var jsonStream = shell.serviceManager.basics.memoryStream;
dictionary.toJSON(jsonStream);
jsonStream.close();
/*The resulting JSON in the stream will look like this:
{
    "name":"Hello World",
    "isVisible":"false",
    "users":["john", "tom"],
    "width":400,
}
*/