Michael Marcin wrote: I find the most useful interface is to just provide a datatype you're
expecting and let the json parser try its best to do the right thing. For example: string raw_json = R"({ data:{ a:"hello", b:"world", c:3, widget:3.5 } })"; [...] struct my_type5 { struct my_data { string a; string b; int c; float widget; } data; }; // these should all just work, with maybe a little bit of // metaprogramming to describe the types to the json library json::deserialize
( json );
I agree. This is, by far, the most intuitive interface. I understand how this can be implemented for data types like map or even Boost.Fusion vector in case of JSON multiple type arrays. However, I have no idea how to implement this in the example above with a struct! Unless of course there is no field name check nor type checking, and the JSON values are just copied sequentially into the struct regardless of field names. Btw I don't even know how to do this without using C++0x extended initializer lists. Otherwise we require some form of reflection in C++. I imagine I should look into Boost.Serialization...? I looked at Boost.Fusion adapt_struct, but that looks quite complicated. Am I missing something? Please let me know what you think. Kind regards, Stephan.
On 04/14/2013 07:19 PM, Stephan Bourgeois wrote:
Otherwise we require some form of reflection in C++. I imagine I should look into Boost.Serialization...? I looked at Boost.Fusion adapt_struct, but that looks quite complicated.
Yes, structs have to be adapted.
participants (2)
-
Bjorn Reese
-
Stephan Bourgeois