FIX: The value maybe string or int

JIRA: [STUDIO-13018]
Change-Id: I4af161431fb51e1e0234bc37de8346b45f3ca4b7
(cherry picked from commit 4e2934685033c352ea2c3baded585381c285a90d)
This commit is contained in:
xin.zhang
2025-07-14 16:45:15 +08:00
committed by Noisyfox
parent 042cf84614
commit 1331e51dae

View File

@@ -2989,7 +2989,18 @@ int MachineObject::parse_json(std::string payload, bool key_field_only)
}
}
if (j_pre["print"].contains("plate_idx")){ // && m_plate_index == -1
m_plate_index = j_pre["print"]["plate_idx"].get<int>();
if (j_pre["print"]["plate_idx"].is_number())
{
m_plate_index = j_pre["print"]["plate_idx"].get<int>();
}
else if (j_pre["print"]["plate_idx"].is_string())
{
try
{
m_plate_index = std::stoi(j_pre["print"]["plate_idx"].get<std::string>());
}
catch (...) { BOOST_LOG_TRIVIAL(error) << "parse_json: failed to convert plate_idx to int"; }
}
}
}
if (j_pre.contains("system")) {