JSONException if T cannot hold the contents of this JSONValue
1 import std.exception; 2 string s = 3 `{ 4 "a": 123, 5 "b": 3.1415, 6 "c": "text", 7 "d": true, 8 "e": [1, 2, 3], 9 "f": { "a": 1 } 10 }`; 11 12 struct a { } 13 14 immutable json = parseJSON(s); 15 assert(json["a"].get!double == 123.0); 16 assert(json["a"].get!int == 123); 17 assert(json["b"].get!double == 3.1415); 18 assertThrown(json["b"].get!int); 19 assert(json["c"].get!string == "text"); 20 assert(json["d"].get!bool == true); 21 assertNotThrown(json["e"].get!(JSONValue[])); 22 assertNotThrown(json["f"].get!(JSONValue[string])); 23 static assert(!__traits(compiles, json["a"].get!a)); 24 assertThrown(json["e"].get!float); 25 assertThrown(json["d"].get!(JSONValue[string])); 26 assertThrown(json["f"].get!(JSONValue[]));
Generic type value getter A convenience getter that returns this JSONValue as the specified D type. Note: only numeric, bool, string, JSONValue[string] and JSONValue[] types are accepted