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

Side by Side Diff: sdk/lib/json/json.dart

Issue 12114021: Use browsers JSON.parse for parsing JSON. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/libraries.dart ('k') | tests/json/json_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 17 matching lines...) Expand all
28 if (cause != null) { 28 if (cause != null) {
29 return "Calling toJson method on object failed."; 29 return "Calling toJson method on object failed.";
30 } else { 30 } else {
31 return "Object toJson method returns non-serializable value."; 31 return "Object toJson method returns non-serializable value.";
32 } 32 }
33 } 33 }
34 } 34 }
35 35
36 36
37 /** 37 /**
38 * Parses [json] and build the corresponding parsed JSON value. 38 * Parses [json] and builds 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 [reviver] function, if provided, is called once for each object
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 reviver will be used as the value of that property instead of the parsed
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 external parse(String json, [reviver(var key, var value)]);
54
55 _parse(String json, [reviver(var key, var value)]) {
kasperl 2013/02/06 07:07:11 If this code is only used by the VM, it shouldn't
sra1 2013/02/06 17:22:39 The code can still be used by someone who needs th
53 BuildJsonListener listener; 56 BuildJsonListener listener;
54 if (reviver == null) { 57 if (reviver == null) {
55 listener = new BuildJsonListener(); 58 listener = new BuildJsonListener();
56 } else { 59 } else {
57 listener = new ReviverJsonListener(reviver); 60 listener = new ReviverJsonListener(reviver);
58 } 61 }
59 new JsonParser(json, listener).parse(); 62 new JsonParser(json, listener).parse();
60 return listener.result; 63 return listener.result;
61 } 64 }
62 65
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 first = false; 798 first = false;
796 }); 799 });
797 sb.add('}'); 800 sb.add('}');
798 seen.removeLast(); 801 seen.removeLast();
799 return true; 802 return true;
800 } else { 803 } else {
801 return false; 804 return false;
802 } 805 }
803 } 806 }
804 } 807 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/libraries.dart ('k') | tests/json/json_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698