Posted: 03/18/10 21:58:06
-- Modified: 03/18/10 23:24:45
by
stanleyxu2005
-- Modified 2 Times
kris wrote:
stanleyxu2005 wrote:
Another question: Why Json does not provide a serialize (or toString) method. It is very inconvenience to print a Json object as string. We have to declare a delegate function first.
Yeah, that's a pain ... will fix it tonight (the delegate used is often part of an existing output stream, so toString() has historically not been needed so much).
A better name would be serialize. What does it sound like?
I just report another two problems of Json here, if you already want to fix Json problem very soon.
PROBLEM 1: Parsing negative integer failed
auto json = new Json!(char);
json.parse(`{"jsonrpc":"2.0", "error": {"code": 32700, "message": "Parse error"}, "id": null}`); // PASSED
json.parse(`{"jsonrpc":"2.0", "error": {"code": -32700, "message": "Parse error"}, "id": null}`); // object.Exception: Expected " before member name
PROBLEM 2: Integer should not be converted to a Float.
In my application, I want to send a Json RPC error response, but the error code is coded as -32700.00 not -32700.
auto json = new Json!(char);
json.value = json.object(json.pair("code", json.value(-32700)));
// output -> {"code": -32700.00}
// expected -> {"code": -32700}
assert(json.value("code").toNumber == -32700); // PASSED
The function toNumber returns a float, but it is OK. We can convert it to the correct type easily.
But the string representation should not be a float. If we send Json string to other application in other language, it may be regarded as an error.
blog: stanleyxu's area51
project: gosurf webbrowser