Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.convert; | 5 part of dart.convert; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Error thrown by JSON serialization if an object cannot be serialized. | 8 * Error thrown by JSON serialization if an object cannot be serialized. |
| 9 * | 9 * |
| 10 * The [unsupportedObject] field holds that object that failed to be serialized. | 10 * The [unsupportedObject] field holds that object that failed to be serialized. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 | 46 |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * An instance of the default implementation of the [JsonCodec]. | 49 * An instance of the default implementation of the [JsonCodec]. |
| 50 * | 50 * |
| 51 * This instance provides a convenient access to the most common JSON | 51 * This instance provides a convenient access to the most common JSON |
| 52 * use cases. | 52 * use cases. |
| 53 * | 53 * |
| 54 * Examples: | 54 * Examples: |
| 55 * | 55 * |
| 56 * var encoded = JSON.encode([1, 2, { "a": null }]); | 56 * var encoded = JSON.encode([1, 2, { "a": null }]); |
|
Lasse Reichstein Nielsen
2015/09/30 06:20:31
Make sure this is indented enough. It seems to be
| |
| 57 * var decoded = JSON.decode('["foo", { "bar": 499 }]'); | 57 * var decoded = JSON.decode('["foo", { "bar": 499 }]'); |
| 58 */ | 58 */ |
| 59 const JsonCodec JSON = const JsonCodec(); | 59 const JsonCodec JSON = const JsonCodec(); |
| 60 | 60 |
| 61 typedef _Reviver(var key, var value); | 61 typedef _Reviver(var key, var value); |
| 62 typedef _ToEncodable(var o); | 62 typedef _ToEncodable(var o); |
| 63 | 63 |
| 64 | 64 |
| 65 /** | 65 /** |
| 66 * A [JsonCodec] encodes JSON objects to strings and decodes strings to | 66 * A [JsonCodec] encodes JSON objects to strings and decodes strings to |
| 67 * JSON objects. | 67 * JSON objects. |
| 68 * | |
| 69 * Examples: | |
| 70 * | |
| 71 * var encoded = JSON.encode([1, 2, { "a": null }]); | |
| 72 * var decoded = JSON.decode('["foo", { "bar": 499 }]'); | |
| 68 */ | 73 */ |
| 69 class JsonCodec extends Codec<Object, String> { | 74 class JsonCodec extends Codec<Object, String> { |
| 70 final _Reviver _reviver; | 75 final _Reviver _reviver; |
| 71 final _ToEncodable _toEncodable; | 76 final _ToEncodable _toEncodable; |
| 72 | 77 |
| 73 /** | 78 /** |
| 74 * Creates a `JsonCodec` with the given reviver and encoding function. | 79 * Creates a `JsonCodec` with the given reviver and encoding function. |
| 75 * | 80 * |
| 76 * The [reviver] function is called during decoding. It is invoked | 81 * The [reviver] function is called during decoding. It is invoked |
| 77 * once for each object or list property that has been parsed. | 82 * once for each object or list property that has been parsed. |
| (...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1056 buffer.setRange(index, end, indent); | 1061 buffer.setRange(index, end, indent); |
| 1057 index = end; | 1062 index = end; |
| 1058 } else { | 1063 } else { |
| 1059 for (int i = 0; i < indentLength; i++) { | 1064 for (int i = 0; i < indentLength; i++) { |
| 1060 writeByte(indent[i]); | 1065 writeByte(indent[i]); |
| 1061 } | 1066 } |
| 1062 } | 1067 } |
| 1063 } | 1068 } |
| 1064 } | 1069 } |
| 1065 } | 1070 } |
| OLD | NEW |