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:
lrn@google.com 2013-08-28 08:25:34 +00:00
parent 6764a2462c
commit 3408c5bc88
4 changed files with 8 additions and 4 deletions

View file

@ -133,7 +133,7 @@ class _ReviverJsonListener extends _BuildJsonListener {
}
get result {
return reviver("", value);
return reviver(null, value);
}
}

View file

@ -90,5 +90,5 @@ _convertJsonToDart(json, reviver(key, value)) {
return map;
}
return revive("", walk(json));
return revive(null, walk(json));
}

View file

@ -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);
}

View file

@ -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}');