Reputation:
So I am trying to read every string inside a JSON file using https://github.com/nlohmann/json and push the strings inside a map. I need this to read every string in a language file for serialization. EXAMPLE:
{
"StringToRead1" : "Test",
"StringToRead2" : "Another Test"
}
So i tried to use an iterator and push everything in:
std::ifstream iStream(filePath);
if(!iStream.is_open()) { std::cout << "Cannot open the strings language file.\n"; return -1; }
nlohmann::json json = nlohmann::json::parse(iStream);
for(auto a = json.begin(); a != json.end(); ++a) {
std::map<std::string, std::string>::iterator iterator = m_Strings.begin();
m_Strings.insert(iterator, std::pair<std::string, std::string>(a.key, a.value));
}
I am getting these compile errors: error C3867: 'nlohmann::detail::iter_impl>>>::key': syntax not standard; use'&' to create a pointer error C3867: 'nlohmann::detail::iter_impl>>>::value': syntax not standard; use'&' to create a pointer
Thanks for the help, i hope i was clear enough.
SOLUTION: a.key() and a.value() instead of a.key and a.value THANK YOU
Upvotes: 0
Views: 124
Reputation: 1256
the key and value are function call so you need to use function operator:
for(auto a = json.begin(); a != json.end(); ++a) {
std::map<std::string, std::string>::iterator iterator = m_Strings.begin();
m_Strings.insert(iterator, std::pair<std::string, std::string>(a.key(), a.value()));
}
insted of
for(auto a = json.begin(); a != json.end(); ++a) {
std::map<std::string, std::string>::iterator iterator = m_Strings.begin();
m_Strings.insert(iterator, std::pair<std::string, std::string>(a.key, a.value));
}
Upvotes: 1