From e0dfe1a1106ab6fd315114e0960d38dae131b746 Mon Sep 17 00:00:00 2001 From: zhrenqiang Date: Wed, 3 Sep 2025 19:00:17 +0800 Subject: [PATCH] add json obj try-catch Change-Id: Ic1c148531676dc59f5805b859152e934ea9f05a1 Signed-off-by: zhrenqiang --- .../inner_api/appexecfwk_base/include/json_util.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/interfaces/inner_api/appexecfwk_base/include/json_util.h b/interfaces/inner_api/appexecfwk_base/include/json_util.h index f9921fd2b4..c97bd5bb8c 100644 --- a/interfaces/inner_api/appexecfwk_base/include/json_util.h +++ b/interfaces/inner_api/appexecfwk_base/include/json_util.h @@ -83,7 +83,12 @@ void CheckArrayType( } } if (parseResult == ERR_OK) { - data = jsonObject.at(key).get(); + try { + data = jsonObject.at(key).get(); + } catch (nlohmann::json::exception &e) { + APP_LOGE("type error %{public}s : %{public}s", key.c_str(), e.what()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + } } break; case ArrayType::NUMBER: @@ -130,7 +135,12 @@ void GetValueIfFindKey(const nlohmann::json &jsonObject, const nlohmann::detail: parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; break; } - data = jsonObject.at(key).get(); + try { + data = jsonObject.at(key).get(); + } catch (nlohmann::json::exception &e) { + APP_LOGE("type error %{public}s : %{public}s", key.c_str(), e.what()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + } break; case JsonType::ARRAY: if (!jsonObject.at(key).is_array()) { -- Gitee