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

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

Issue 9387007: Make lists parsed by JSON untyped. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | « no previous file | no next file » | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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("json"); 5 #library("json");
6 6
7 // Pure Dart implementation of JSON protocol. 7 // Pure Dart implementation of JSON protocol.
8 8
9 /** 9 /**
10 * Utility class to parse JSON and serialize objects to JSON. 10 * Utility class to parse JSON and serialize objects to JSON.
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 389
390 case JsonToken.LBRACKET: 390 case JsonToken.LBRACKET:
391 return _parseList(); 391 return _parseList();
392 392
393 default: 393 default:
394 throw 'Unexpected token: ${token}'; 394 throw 'Unexpected token: ${token}';
395 } 395 }
396 } 396 }
397 397
398 _parseObject() { 398 _parseObject() {
399 Map<String, Object> object = new Map<String, Object>(); 399 final object = {};
400 400
401 _parseSequence(JsonToken.RBRACE, (JsonToken token) { 401 _parseSequence(JsonToken.RBRACE, (JsonToken token) {
402 _assertTokenKind(token, JsonToken.STRING); 402 _assertTokenKind(token, JsonToken.STRING);
403 final String key = token.str; 403 final String key = token.str;
404 404
405 token = _tokenizer.next(); 405 token = _tokenizer.next();
406 _assertTokenKind(token, JsonToken.COLON); 406 _assertTokenKind(token, JsonToken.COLON);
407 407
408 token = _tokenizer.next(); 408 token = _tokenizer.next();
409 final value = _parseValue(token); 409 final value = _parseValue(token);
410 410
411 object[key] = value; 411 object[key] = value;
412 }); 412 });
413 413
414 return object; 414 return object;
415 } 415 }
416 416
417 _parseList() { 417 _parseList() {
418 List<Object> list = new List<Object>(); 418 final list = [];
419 419
420 _parseSequence(JsonToken.RBRACKET, (JsonToken token) { 420 _parseSequence(JsonToken.RBRACKET, (JsonToken token) {
421 final value = _parseValue(token); 421 final value = _parseValue(token);
422 list.add(value); 422 list.add(value);
423 }); 423 });
424 424
425 return list; 425 return list;
426 } 426 }
427 427
428 void _parseSequence(int endTokenKind, void parseElement(JsonToken token)) { 428 void _parseSequence(int endTokenKind, void parseElement(JsonToken token)) {
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 }); 592 });
593 _sb.add('}'); 593 _sb.add('}');
594 _seen.removeLast(); 594 _seen.removeLast();
595 return; 595 return;
596 596
597 default: 597 default:
598 throw const JsonUnsupportedObjectType(); 598 throw const JsonUnsupportedObjectType();
599 } 599 }
600 } 600 }
601 } 601 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698