Chromium Code Reviews| Index: sdk/lib/convert/json.dart |
| diff --git a/sdk/lib/convert/json.dart b/sdk/lib/convert/json.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..19782eef7398c81cdda5a2a92f05175f22d2d54c |
| --- /dev/null |
| +++ b/sdk/lib/convert/json.dart |
| @@ -0,0 +1,43 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +part of dart.convert; |
| + |
| +/** |
| + * A [JsonEncoder] converts Json-objects to strings. |
| + */ |
| +class JsonEncoder extends Converter<Object, String> { |
| + JsonEncoder(); |
| + |
| + /** |
| + * Converts the given Json-object [o] and returns its stringified |
|
Lasse Reichstein Nielsen
2013/07/12 11:50:47
Specify whay "Json-object" is (JSON object).
It's
floitsch
2013/07/12 16:09:15
copied the documentation from `stringify`.
|
| + * Json representation. |
|
Lasse Reichstein Nielsen
2013/07/12 11:50:47
Json -> JSON.
Drop "stringified", JSON is a string
floitsch
2013/07/12 16:09:15
removed.
|
| + */ |
| + String convert(Object o) => OLD_JSON_LIB.stringify(o); |
| +} |
| + |
| +typedef _Reviver(var key, var value); |
| + |
| + |
| +/** |
| + * A [JsonDecoder] parses Json strings and builds the corresponding |
|
Lasse Reichstein Nielsen
2013/07/12 11:50:47
JSON strings
JSON objects (if defined above)
floitsch
2013/07/12 16:09:15
Changed to
"JSON strings and builds the correspond
|
| + * Json objects. |
| + */ |
| +class JsonDecoder extends Converter<String, Object> { |
| + final _Reviver _reviver; |
| + /** |
| + * Constructs a new JsonDecoder. |
| + * |
| + * The [reviver] may be `null`. |
| + */ |
| + JsonDecoder(reviver(var key, var value)) : this._reviver = reviver; |
| + |
| + /** |
| + * Converts the given Json-string [input] to the corresponding object. |
|
Lasse Reichstein Nielsen
2013/07/12 11:50:47
JSON string.
floitsch
2013/07/12 16:09:15
copied the original description.
|
| + * |
| + * If `this` was initialized with a reviver, then the parsing operation |
| + * invokes the reviver on every object or list property that has been parsed. |
| + */ |
| + Object convert(String input) => OLD_JSON_LIB.parse(input, _reviver); |
| +} |