Dart API Referencedart:json

dart:json library

Functions

void printOn(Object object, StringBuffer output) #

Serializes object into output stream.

Performs the same operations as stringify but outputs the resulting string to an existing StringBuffer instead of creating a new String.

If serialization fails by throwing, some data might have been added to output, but it won't contain valid JSON text.

void printOn(Object object, StringBuffer output) {
 return _JsonStringifier.printOn(object, output);
}

String stringify(Object object) #

Serializes object into a JSON string.

Directly serializable values are num, String, bool, and Null, as well as some List and Map values. For List, the elements must all be serializable. For Map, the keys must be String and the values must be serializable.

If a value is any other type is attempted serialized, a "toJson()" method is invoked on the object and the result, which must be a directly serializable value, is serialized instead of the original value.

If the object does not support this method, throws, or returns a value that is not directly serializable, a JsonUnsupportedObjectError exception is thrown. If the call throws (including the case where there is no nullary "toJson" method, the error is caught and stored in the JsonUnsupportedObjectError's cause field.

If a List or Map contains a reference to itself, directly or through other lists or maps, it cannot be serialized and a JsonCyclicError is thrown.

Json Objects should not change during serialization. If an object is serialized more than once, stringify is allowed to cache the JSON text for it. I.e., if an object changes after it is first serialized, the new values may or may not be reflected in the result.

String stringify(Object object) {
 return _JsonStringifier.stringify(object);
}

dynamic parse(String json, [reviver(key, value)]) #

Parses json and build the corresponding parsed JSON value.

Parsed JSON values are of the types num, String, bool, Null, Lists of parsed JSON values or Maps from String to parsed JSON values.

The optional revivier function, if provided, is called once for each object or list property parsed. The arguments are the property name (String) or list index (int), and the value is the parsed value. The return value of the revivier will be used as the value of that property instead the parsed value.

Throws FormatException if the input is not valid JSON text.

external parse(String json, [reviver(var key, var value)]);

Abstract Classes

Classes

Exceptions