-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Unpack list of integers to a std::vector<int> #1460
Comments
I cannot reproduce the problem. This code works: #include "json.hpp"
#include <iostream>
using json = nlohmann::json;
int main() {
json j = R"(
{
"my_list" : [1,2,3]
}
)"_json;
auto v = j["my_list"].get<std::vector<int>>();
for (auto i : v)
{
std::cout << i << std::endl;
}
} Output:
|
Which version of the library are you using? What is the exact error message you encounter? |
My apologies. It works on my end also. I failed to isolate a testcase and my JSON was malformed. Might I make a couple of suggestions? Firstly, in the documentation, it would be nice to present packing and unpacking hand-in-hand. Maybe an "Unpacking Examples" section? Also, I wonder if It might be possible to overload assignment= operator on |
Please look at #958 for more information. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Is there any way to unpack:
into a
std:vector<int>
?I can't find any mention, and
std::vector<int> v = j["my_list"];
fails, as doesj["my_list"].get<std::vector<int>>()
(Crosslinked to https://stackoverflow.com/questions/54389742/use-nlohmann-json-to-unpack-list-of-integers-to-a-stdvectorint)
The text was updated successfully, but these errors were encountered: