-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
init error #92
Comments
Hi, in 1), you're initializing the reward with an object type (aka map). This is exactly the same as initializing a map like this: std::map<std::string, std::string> m = {
{"key", "val"},
{"key", "xxx"}
};
printf("%s\n", m["key"].c_str()); the result will be: Assuming you want reward to be an array of objects, you would need to: json j = {
{ "limit", 1000 },
{ "reward",
{
{{ "chip", 1000 }},
{{ "chip", 2000 }},
{{ "chip", 3000 }}
}
}
}; which gives you a
If you want reward to be an array of arrays, then most likely json::array constructs are needed. Hope it helps, |
Think you very mush. I was hoping for your example, It is very helpful to me. Now I know the reason. Buf if for some reason, I just want a result as Thanks again |
Hi @likebeta, the problem is that C++ only supports
So in your example So when you want this to be treated as array, you need to tell it explicitly by json::array({
{ "chip", 1000 }, { "chip", 2000 }, { "chip", 3000 }
}) In fact, this is one of the few situations where you need to help the class to understand what you want. Sorry for the inconvenience. And thanks to @ropuls for the quick explanation. Cheers |
code:
output:
It is strange in case 1, why get this result?
The text was updated successfully, but these errors were encountered: