| 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 /** | 5 /** |
| 6 * Utilities for encoding and decoding JSON (JavaScript Object Notation) data. | 6 * Utilities for encoding and decoding JSON (JavaScript Object Notation) data. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 library json; | 9 library json; |
| 10 | 10 |
| (...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 } | 762 } |
| 763 | 763 |
| 764 /** | 764 /** |
| 765 * Serializes a [num], [String], [bool], [Null], [List] or [Map] value. | 765 * Serializes a [num], [String], [bool], [Null], [List] or [Map] value. |
| 766 * | 766 * |
| 767 * Returns true if the value is one of these types, and false if not. | 767 * Returns true if the value is one of these types, and false if not. |
| 768 * If a value is both a [List] and a [Map], it's serialized as a [List]. | 768 * If a value is both a [List] and a [Map], it's serialized as a [List]. |
| 769 */ | 769 */ |
| 770 bool stringifyJsonValue(final object) { | 770 bool stringifyJsonValue(final object) { |
| 771 if (object is num) { | 771 if (object is num) { |
| 772 // TODO: use writeOn. | 772 if (!object.isFinite) return false; |
| 773 sink.write(numberToString(object)); | 773 sink.write(numberToString(object)); |
| 774 return true; | 774 return true; |
| 775 } else if (identical(object, true)) { | 775 } else if (identical(object, true)) { |
| 776 sink.write('true'); | 776 sink.write('true'); |
| 777 return true; | 777 return true; |
| 778 } else if (identical(object, false)) { | 778 } else if (identical(object, false)) { |
| 779 sink.write('false'); | 779 sink.write('false'); |
| 780 return true; | 780 return true; |
| 781 } else if (object == null) { | 781 } else if (object == null) { |
| 782 sink.write('null'); | 782 sink.write('null'); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 first = false; | 818 first = false; |
| 819 }); | 819 }); |
| 820 sink.write('}'); | 820 sink.write('}'); |
| 821 seen.remove(object); | 821 seen.remove(object); |
| 822 return true; | 822 return true; |
| 823 } else { | 823 } else { |
| 824 return false; | 824 return false; |
| 825 } | 825 } |
| 826 } | 826 } |
| 827 } | 827 } |
| OLD | NEW |