MCPcopy Create free account
hub / github.com/OriginQ/QPanda-2 / parse_task_result

Method parse_task_result

Extensions/PilotOSMachine/QPilotMachine.cpp:3168–3199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3166
3167#endif
3168bool QPilotMachine::parse_task_result(const std::string& result_str,
3169 std::map<std::string, double>& result_mp)
3170{
3171 JsonParser json_parser_res;
3172 if (!json_parser_res.load_json(result_str))
3173 {
3174 PTraceError("Error: Failed to parse str: " << result_str);
3175 return false;
3176 }
3177
3178 auto& res_str = json_parser_res.get_json_obj();
3179 if (res_str.HasMember("key") && res_str.HasMember("value"))
3180 {
3181 auto key_vec = res_str["key"].GetArray();
3182 auto value_vec = res_str["value"].GetArray();
3183
3184 auto sizek = key_vec.Size();
3185 auto sizev = value_vec.Size();
3186 if (sizek == sizev)
3187 {
3188 for (auto i = 0; i < sizek; ++i)
3189 {
3190 auto key = key_vec[i].GetString();
3191 auto val = value_vec[i].IsDouble() ? value_vec[i].GetDouble() : (double)value_vec[i].GetInt();
3192
3193 result_mp.insert(make_pair(key, val));
3194 }
3195 }
3196 }
3197
3198 return true;
3199}
3200
3201bool QPilotMachine::parse_task_result(const std::vector<std::string>& result_vec,
3202 std::vector<std::map<std::string, double>>& result_mp_vec)

Callers 4

export_extension_classFunction · 0.45

Calls 12

load_jsonMethod · 0.80
HasMemberMethod · 0.80
GetArrayMethod · 0.80
GetStringMethod · 0.80
GetDoubleMethod · 0.80
GetIntMethod · 0.80
SizeMethod · 0.45
insertMethod · 0.45
sizeMethod · 0.45
parseMethod · 0.45
push_backMethod · 0.45
clearMethod · 0.45

Tested by 3