On Wednesday, 2 January 2013 at 17:02:48 UTC, Chris wrote:
I was playing around with std.conv.parse's mechanism for
parsing associative arrays from strings (cf.
http://dlang.org/phobos/std_conv.html#parse). A handy feature
as it would allow user-friendly input formats that can be
transformed into a D-array. However, the parser is very finicky
and expects the string to be exactly as if it were a hard-coded
D-array:
void main(string[] args) {
auto asso = "[\"key1\":\"value1\", \"key2\":\"value2\"]";
auto array = parse!(string[string], string)(asso);
foreach (k, v; array) {
writefln("%s : %s", k, v);
}
}
You could reduce burden by using raw strings:
auto asso = `["key1":"value1", "key2":"value2"]`;
Or is there something I have overlooked?
What bearophile said.