-
-
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
Problem getting vector (array) of strings #44
Comments
Dear Amir, thanks for reporting! It sure looks like a bug. I shall have a look once I'm back from holidays. All the best |
I could reproduce the bug. |
Unfortunately, I cannot find a solution right now. I'll check again later. |
The last commit (1bdb6ac) fixed this issue. The following code compiles as expected: #include <src/json.hpp>
using nlohmann::json;
int main()
{
auto j = R"(
{
"names": ["Tim", "Tom"],
"num": [1, 2]
}
)"_json;
std::vector<std::string> names = j["names"];
for (auto i : names)
{
std::cout << i << " ";
}
// prints: Tim Tom
} |
Thanks! :) |
Hi @nlohmann , separating the definition and declaration doesnt work again. Any solution for this? I need this. |
You modified the code slightly and that might affect your code. I think you should either use the |
Sync Fork from Upstream Repo
Considering the JSON below,
I want to get a vector of string. I realized that I could only use
auto a = json["name"]
and then process it using for-range loop. However, if I want to explicitly define the return type then I will get an error. For instance, bothvector<string> names = j["names"]
andvector<string> names = j["names"].get<vector<string>>()
will give me an error:I can see that json library couldn't cast to
vector<string>
; however, it will work if I want to getnum
even explicitly like this:vector<float> f = j["num"].get<vector<float>>()
.Now, I'm wondering if I am doing it wrong or it's not implemented?
Thanks,
Amir.
The text was updated successfully, but these errors were encountered: