-
struct a_struct_with_vector
{
std::string id;
std::vector<int> data;
}
void to_json(json& j, const a_struct_with_vector& data)
{
j[data.id] = data;
}
a_struct_with_vector data;
data.id = "hello";
data.data.push_back(1);
data.data.pus_back(2);
// then, we put the data to json and dump it
json j{data};
j.dump();
// and we got the result [{"hello": [1, 2]}]
// now there, how can I make data.data's result surrounded by braces(associative container are) instead of square brackets?
// like [{"hello": {1, 2}}] :)
// by the way, why it surrounded by `[{ }]` instead of `{ }` |
Beta Was this translation helpful? Give feedback.
Answered by
nlohmann
Jun 16, 2021
Replies: 2 comments 2 replies
-
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Can you replace json j{data}; with json j = data; |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Life4gal
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you replace
with