Strange behaviour of to!string and JSON
    wobbles via Digitalmars-d 
    digitalmars-d at puremagic.com
       
    Thu Dec  3 02:55:11 PST 2015
    
    
  
On Thursday, 3 December 2015 at 08:46:44 UTC, Suliman wrote:
> void login(HTTPServerRequest req, HTTPServerResponse res)
> {
>  Json request = req.json;
>  writeln(to!string(request["username"]));
>  writeln(request["username"].to!string);
> }
>
> Why first code print output with quotes, and second not?
> "asd"
> asd
I regularly use
request["username"].get!string; in these cases, as I find it 
reads better and is more consistent with what you're actually 
doing.
http://vibed.org/api/vibe.data.json/Json.get
Also, I think this is the case (haven't used it in a while), 
get!string will fail if the item it's getting ISNT a string, 
while to!string wont.
    
    
More information about the Digitalmars-d
mailing list