Incorrect convert map to json when key cannot construct an string i.e. int #2564
Closed
1 of 3 tasks
Labels
solution: wontfix
the issue will not be fixed (either it is impossible or deemed out of scope)
What is the issue you have?
I'm now using nlohmann/json to convert my variables in C++. I find the conversion the map whose keys cannot construct an std::string to json is not run as expected. for example, the map with key is int type.
Please describe the steps to reproduce the issue.
Can you provide a small but working code example?
Example Code:
std::map<int, int> c_map_1 { {1, 101}, {2, 202}, {3, 303} };
json j_map_1(c_map_1);
std::map<std::string, int> c_map_2 { {"one", 1}, {"two", 2}, {"three", 3} };
json j_map_2(c_map_2);
std::map<int, std::string> c_map_3 { {1, "one"}, {2, "two"}, {3, "three"} };
json j_map_3(c_map_3);
cout << j_map_1 << endl << j_map_2 << endl << j_map_3 << endl;
Run Result:
[[1,101],[2,202],[3,303]]
{"one":1,"three":3,"two":2}
[[1,"one"],[2,"two"],[3,"three"]]
Expected Result:
{"1":101,"2":202,"3":303}
{"one":1,"three":3,"two":2}
{"1":"one","2":"two","3":"three"}
Which compiler and operating system are you using?
Which version of the library did you use?
develop
branchThe text was updated successfully, but these errors were encountered: