mirror of
https://github.com/dart-lang/sdk
synced 2024-09-20 01:19:15 +00:00
Make the result of JSON.decode be marked by "null" in the reviver.
They are currently marked by "", which can match a property as well. R=floitsch@google.com Review URL: https://codereview.chromium.org//23688003 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@26768 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
6764a2462c
commit
3408c5bc88
|
@ -133,7 +133,7 @@ class _ReviverJsonListener extends _BuildJsonListener {
|
|||
}
|
||||
|
||||
get result {
|
||||
return reviver("", value);
|
||||
return reviver(null, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,5 +90,5 @@ _convertJsonToDart(json, reviver(key, value)) {
|
|||
return map;
|
||||
}
|
||||
|
||||
return revive("", walk(json));
|
||||
return revive(null, walk(json));
|
||||
}
|
||||
|
|
|
@ -29,6 +29,10 @@ export "dart:convert" show JsonUnsupportedObjectError, JsonCyclicError;
|
|||
* Throws [FormatException] if the input is not valid JSON text.
|
||||
*/
|
||||
parse(String json, [reviver(var key, var value)]) {
|
||||
if (reviver != null) {
|
||||
var original = reviver;
|
||||
reviver = (key, value) => original(key == null ? "" : key, value);
|
||||
}
|
||||
return JSON.decode(json, reviver: reviver);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,12 +22,12 @@ main() {
|
|||
|
||||
// Test that the reviver is passed to the decoder.
|
||||
var decoded = JSON.decode('{"p": 5}', reviver: (k, v) {
|
||||
if (k == "") return v;
|
||||
if (k == null) return v;
|
||||
return v * 2;
|
||||
});
|
||||
Expect.equals(10, decoded["p"]);
|
||||
var jsonWithReviver = new JsonCodec.withReviver((k, v) {
|
||||
if (k == "") return v;
|
||||
if (k == null) return v;
|
||||
return v * 2;
|
||||
});
|
||||
decoded = jsonWithReviver.decode('{"p": 5}');
|
||||
|
|
Loading…
Reference in a new issue