Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Unified Diff: sdk/lib/convert/json.dart

Issue 19000006: First version of Codecs and Converters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revert sdk/lib/json change. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
+}

Powered by Google App Engine
This is Rietveld 408576698