| 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 // JSON parsing and serialization. | 5 // JSON parsing and serialization. |
| 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 29 matching lines...) Expand all Loading... |
| 40 * JSON values. | 40 * JSON values. |
| 41 * | 41 * |
| 42 * The optional [revivier] function, if provided, is called once for each | 42 * The optional [revivier] function, if provided, is called once for each |
| 43 * object or list property parsed. The arguments are the property name | 43 * object or list property parsed. The arguments are the property name |
| 44 * ([String]) or list index ([int]), and the value is the parsed value. | 44 * ([String]) or list index ([int]), and the value is the parsed value. |
| 45 * The return value of the revivier will be used as the value of that property | 45 * The return value of the revivier will be used as the value of that property |
| 46 * instead the parsed value. | 46 * instead the parsed value. |
| 47 * | 47 * |
| 48 * Throws [FormatException] if the input is not valid JSON text. | 48 * Throws [FormatException] if the input is not valid JSON text. |
| 49 */ | 49 */ |
| 50 parse(String json, [reviver(var key, var value)]) { | 50 external parse(String json, [reviver(var key, var value)]); |
| 51 |
| 52 _parse(String json, reviver(var key, var value)) { |
| 51 BuildJsonListener listener; | 53 BuildJsonListener listener; |
| 52 if (reviver == null) { | 54 if (reviver == null) { |
| 53 listener = new BuildJsonListener(); | 55 listener = new BuildJsonListener(); |
| 54 } else { | 56 } else { |
| 55 listener = new ReviverJsonListener(reviver); | 57 listener = new ReviverJsonListener(reviver); |
| 56 } | 58 } |
| 57 new JsonParser(json, listener).parse(); | 59 new JsonParser(json, listener).parse(); |
| 58 return listener.result; | 60 return listener.result; |
| 59 } | 61 } |
| 60 | 62 |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 first = false; | 795 first = false; |
| 794 }); | 796 }); |
| 795 sb.add('}'); | 797 sb.add('}'); |
| 796 seen.removeLast(); | 798 seen.removeLast(); |
| 797 return true; | 799 return true; |
| 798 } else { | 800 } else { |
| 799 return false; | 801 return false; |
| 800 } | 802 } |
| 801 } | 803 } |
| 802 } | 804 } |
| OLD | NEW |