我使用这个库进行 json 解析https://github.com/nlohmann/json
我需要解析这个 json 文件
{
"emulators": [
{
"general_info": {
"dev_id": "0123456789",
"model": "my_model",
"model_full": "my_full_model",
"serial_num": "my_serial_num"
}
}
]
}
我正在努力做到这一点
void EmulatorCameraConfigParser::GetEmulatorContextObjFrom(std::string path_to_configuration_json, std::vector<emulator_context::EmulatorContextObj> * out_arr)
{
json jf = Utils::get_json_data(path_to_configuration_json);
if (jf == nullptr)
{
//TODO print - "Configuration json file for TV_CamFromFiles is null";
}
else
{
try
{
for (auto& elem : jf[EMULATORS])
{
emulator_context::EmulatorContextObj tmp;
tmp.m_general_info = &get_general_info(elem[GENERAL_INFO]);
out_arr->push_back(tmp);
}
}
catch (std::exception& ex)
{
//TODO print error
std::string errMsg = "Exeption during parsing configuration json file for TV_CamFromFiles :: ";
errMsg += ex.what();
}
}
}
emulator_context::GeneralInfo EmulatorCameraConfigParser::get_general_info(const json& json)
{
emulator_context::GeneralInfo generalInfo;
try
{
if (json != nullptr)
{
generalInfo.m_dev_id = json.at(DEV_ID).get<std::string>();
generalInfo.m_serial_num = json.at(SERIAL_NUM).get<int>();
}
}
catch (std::exception& ex)
{
//TODO print this error
std::string errMsg = "Exeption during parsing configuration json file for TV_CamFromFiles :: ";
errMsg += ex.what();
}
return generalInfo;
}
但结果我什么也没得到,所以我几乎可以肯定问题就在这里tmp.m_general_info = &get_general_info(elem[GENERAL_INFO]);
我认为为了获得阻止,general_info
我需要使用其他方式,但是哪一种?