OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library dart.json; | 5 library dart.json; |
6 | 6 |
7 // JSON parsing and serialization. | 7 // JSON parsing and serialization. |
8 | 8 |
9 /** | 9 /** |
10 * Error thrown by JSON serialization if an object cannot be serialized. | 10 * Error thrown by JSON serialization if an object cannot be serialized. |
(...skipping 23 matching lines...) Expand all Loading... | |
34 } | 34 } |
35 | 35 |
36 | 36 |
37 /** | 37 /** |
38 * Parses [json] and build the corresponding parsed JSON value. | 38 * Parses [json] and build the corresponding parsed JSON value. |
39 * | 39 * |
40 * Parsed JSON values are of the types [num], [String], [bool], [Null], | 40 * Parsed JSON values are of the types [num], [String], [bool], [Null], |
41 * [List]s of parsed JSON values or [Map]s from [String] to parsed | 41 * [List]s of parsed JSON values or [Map]s from [String] to parsed |
42 * JSON values. | 42 * JSON values. |
43 * | 43 * |
44 * The optional [revivier] function, if provided, is called once for each | 44 * The optional [revivier] function, if provided, is called once for each object |
Johnni Winther
2013/01/31 08:32:59
revivier -> reviver
sra1
2013/01/31 22:49:36
Done.
| |
45 * object or list property parsed. The arguments are the property name | 45 * or list property parsed. The arguments are the property name ([String]) or |
46 * ([String]) or list index ([int]), and the value is the parsed value. | 46 * list index ([int]), and the value is the parsed value. The return value of |
47 * The return value of the revivier will be used as the value of that property | 47 * the revivier will be used as the value of that property instead the parsed |
Johnni Winther
2013/01/31 08:32:59
ditto
sra1
2013/01/31 22:49:36
Done.
| |
48 * instead the parsed value. | 48 * value. The top level value is passed to the reviver with the empty string as |
49 * a key. | |
49 * | 50 * |
50 * Throws [FormatException] if the input is not valid JSON text. | 51 * Throws [FormatException] if the input is not valid JSON text. |
51 */ | 52 */ |
52 parse(String json, [reviver(var key, var value)]) { | 53 parse(String json, [reviver(var key, var value)]) { |
53 BuildJsonListener listener; | 54 BuildJsonListener listener; |
54 if (reviver == null) { | 55 if (reviver == null) { |
55 listener = new BuildJsonListener(); | 56 listener = new BuildJsonListener(); |
56 } else { | 57 } else { |
57 listener = new ReviverJsonListener(reviver); | 58 listener = new ReviverJsonListener(reviver); |
58 } | 59 } |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
795 first = false; | 796 first = false; |
796 }); | 797 }); |
797 sb.add('}'); | 798 sb.add('}'); |
798 seen.removeLast(); | 799 seen.removeLast(); |
799 return true; | 800 return true; |
800 } else { | 801 } else { |
801 return false; | 802 return false; |
802 } | 803 } |
803 } | 804 } |
804 } | 805 } |
OLD | NEW |