-
What is the issue you have?
I have a variable with std::vector<std::pair<std::string, std::string>> that cannot be deserialised by nlohmann::json.
-
Please describe the steps to reproduce the issue. Can you provide a small but working code example?
JSON: { "options": [{"video_size": ""}, {"framerate": "0"}, {"vcodec": ""}] }
std::vector<std::pair<std::string,std::string>> m_Options;
Non-working Code:
j["options].get_to(m_Options);
Working code:
for (auto &i : j["options"].get<std::vector<std::map<std::string, std::string>>>())
{
m_Options.push_back(*i.begin());
}
-
What is the expected behavior?
Should be able to deserialise to an STL type automatically
-
And what is the actual behavior instead?
Failed to deserialise because wrong type
-
Which compiler and operating system are you using? Is it a supported compiler?
MSVC 2017
-
Did you use a released version of the library or the version from the develop branch?
V3.2.0 - V3.5.0 exhibit this issue
Notes: When serialising m_Options I get:
JSON: { "options":[["video_size",""],["framerate","0"],["vcodec",""]] }
Basically, it treats a std::pair as an array with two elements, rather than a key-value pair.
What is the issue you have?
I have a variable with std::vector<std::pair<std::string, std::string>> that cannot be deserialised by nlohmann::json.
Please describe the steps to reproduce the issue. Can you provide a small but working code example?
JSON: { "options": [{"video_size": ""}, {"framerate": "0"}, {"vcodec": ""}] }
std::vector<std::pair<std::string,std::string>> m_Options;Non-working Code:
j["options].get_to(m_Options);Working code:
What is the expected behavior?
Should be able to deserialise to an STL type automatically
And what is the actual behavior instead?
Failed to deserialise because wrong type
Which compiler and operating system are you using? Is it a supported compiler?
MSVC 2017
Did you use a released version of the library or the version from the
developbranch?V3.2.0 - V3.5.0 exhibit this issue
Notes: When serialising m_Options I get:
JSON: { "options":[["video_size",""],["framerate","0"],["vcodec",""]] }
Basically, it treats a std::pair as an array with two elements, rather than a key-value pair.