From dabbfd23961d6dccfc9878a13c0608c4c79a8331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Tue, 13 May 2025 16:12:43 +0800 Subject: [PATCH 1/3] =?UTF-8?q?cJSON=20=E6=9B=BF=E6=8D=A2=20nlohmann::json?= =?UTF-8?q?=20Signed-off-by:=20=E9=82=B9=E5=8F=8B=E6=9D=BE=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/include/dupdate_json_utils.h | 248 +++++++++++++----- foundations/ability/utils/utils.gni | 2 +- foundations/model/include/business_error.h | 18 -- foundations/model/include/error_message.h | 14 - frameworks/js/napi/update/BUILD.gn | 2 +- interfaces/inner_api/engine/BUILD.gn | 2 +- .../core/ability/adapter/src/config_parse.cpp | 5 +- .../core/ability/model/include/device_info.h | 10 - services/engine/engine_sa.gni | 1 - .../include/update_service_impl_manager.h | 1 + .../firmware/check/include/firmware_icheck.h | 8 +- .../firmware/common/include/firmware_common.h | 19 -- .../common/include/firmware_update_helper.h | 2 - .../include/firmware_check_analyze_utils.h | 8 +- .../src/firmware_check_analyze_utils.cpp | 100 ++++--- .../startup/manage/include/schedule_config.h | 2 +- .../startup/manage/src/schedule_config.cpp | 8 +- 17 files changed, 263 insertions(+), 187 deletions(-) diff --git a/foundations/ability/utils/include/dupdate_json_utils.h b/foundations/ability/utils/include/dupdate_json_utils.h index 6dfc6f57..fd056e1f 100644 --- a/foundations/ability/utils/include/dupdate_json_utils.h +++ b/foundations/ability/utils/include/dupdate_json_utils.h @@ -19,9 +19,9 @@ #include #include #include +#include -#include "nlohmann/json.hpp" - +#include "cJSON.h" #include "update_define.h" namespace OHOS::UpdateService { @@ -36,84 +36,119 @@ enum class JsonParseError { // 当前获取json对象/数组的封装使用的parse方法参数:string输入、无解析回调、解析失败不报异常 class JsonUtils { public: - template - static int32_t GetValueAndSetTo(const nlohmann::json &jsonObject, const std::string &key, T &value) + template static int32_t GetValueAndSetTo(cJSON *jsonObject, const std::string &key, T &value) { - if (jsonObject.find(key) == jsonObject.end()) { + if (!cJSON_HasObjectItem(jsonObject, key.c_str())) + { return CAST_INT(JsonParseError::MISSING_PROP); } - if (!CheckType(jsonObject.at(key), value)) { + + cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (!CheckType(item, value)) + { return CAST_INT(JsonParseError::TYPE_ERROR); } - GetValue(jsonObject, key, value); + + GetValue(item, key, value); return CAST_INT(JsonParseError::ERR_OK); } - static bool ParseAndGetJsonObject(const std::string &jsonStr, nlohmann::json &root) + static cJSON *ParseAndGetJsonObject(const std::string &jsonStr) { - root = nlohmann::json::parse(jsonStr, nullptr, false); - if (root.is_discarded() || !root.is_object()) { - return false; + cJSON *item = cJSON_Parse(jsonStr.c_str()); + if (!item) { + return nullptr; } - return true; + + if (!cJSON_IsObject(item)) + { + cJSON_Delete(item); + return nullptr; + } + + return item; } - static bool ParseAndGetJsonArray(const std::string &jsonStr, nlohmann::json &root) + static cJSON *ParseAndGetJsonArray(const std::string &jsonStr) { - root = nlohmann::json::parse(jsonStr, nullptr, false); - if (root.is_discarded() || !root.is_array()) { - return false; + cJSON *item = cJSON_Parse(jsonStr.c_str()); + if (!item) { + return nullptr; } - return true; + + if (!cJSON_IsArray(item)) + { + cJSON_Delete(item); + return nullptr; + } + + return item; } - static int32_t GetValueAndSetToArray(const nlohmann::json &jsonObject, const std::string &key, - nlohmann::json &value) + static int32_t GetValueAndSetToArray(cJSON *jsonObject, const std::string &key, cJSON **value) { - if (jsonObject.find(key) == jsonObject.end()) { + if (!cJSON_HasObjectItem(jsonObject, key.c_str())) { return CAST_INT(JsonParseError::MISSING_PROP); } - if (!jsonObject.at(key).is_array()) { + + cJSON* item = cJSON_GetObjectItem(jsonObject, key.c_str()); + if (!cJSON_IsArray(item)) { return CAST_INT(JsonParseError::TYPE_ERROR); } - jsonObject.at(key).get_to(value); + + *value = item; return CAST_INT(JsonParseError::ERR_OK); } - static void SetJsonToVector(nlohmann::json &jsonObject, std::vector &vector) + static void SetJsonToVector(cJSON *jsonArray, std::vector &vector) { - if (jsonObject.is_array()) { - for (nlohmann::json::iterator it = jsonObject.begin(); it != jsonObject.end(); ++it) { - if (!it.value().is_string()) { - continue; - } - vector.push_back(static_cast(it.value())); + while (jsonArray != nullptr) { + if (cJSON_IsString(jsonArray)) { + vector.emplace_back(std::string(jsonArray->valuestring)); } + jsonArray = jsonArray->next; } } - static void SetJsonToVector(const nlohmann::json &jsonObject, const std::string &key, + static void SetJsonToVector(cJSON *jsonObject, const std::string &key, std::vector &vector) { if (!IsArray(jsonObject, key)) { return; } - nlohmann::json jsonArray = jsonObject.at(key); + + cJSON *root = cJSON_GetObjectItemCaseSensitive(jsonObject, key.c_str()); + if (root == nullptr) { + return; + } + cJSON *jsonArray = root->child; + if (jsonArray == nullptr) { + return; + } + SetJsonToVector(jsonArray, vector); } - static bool IsArray(const nlohmann::json &jsonObject, const std::string &key) + static bool IsArray(cJSON *jsonObject, const std::string &key) { - if (jsonObject.find(key) == jsonObject.end()) { - return false; - } - return jsonObject.at(key).is_array(); + cJSON *item = cJSON_GetObjectItemCaseSensitive(jsonObject, key.c_str()); + return item && cJSON_IsArray(item); + } + + template void T(cJSON *root, const T &value) + { + return; } template static std::string StructToJsonStr(const T &value) { - nlohmann::json jsonObj(value); - return jsonObj.dump(); + cJSON *root = cJSON_CreateObject(); + T(root, value); // 需针对不同类型特化实现 + char *jsonStr = cJSON_Print(root); + std::string result(jsonStr); + cJSON_Delete(root); + free(jsonStr); + return result; } template static int32_t JsonStrToStruct(const std::string &jsonStr, T &value) @@ -121,78 +156,157 @@ public: if (jsonStr.empty()) { return CAST_INT(JsonParseError::COMMOM_ERROR); } - nlohmann::json jsonObj = nlohmann::json::parse(jsonStr, nullptr, false); - if (!jsonObj.is_discarded() && CheckType(jsonObj, value)) { - value = jsonObj.get(); + + cJSON *jsonObj = cJSON_Parse(jsonStr.c_str()); + if (!jsonObj) + { + return CAST_INT(JsonParseError::COMMOM_ERROR); + } + + if (CheckType(jsonObj, value)) + { + value = T(jsonObj); // 需针对不同类型特化实现 + cJSON_Delete(jsonObj); return CAST_INT(JsonParseError::ERR_OK); } + + cJSON_Delete(jsonObj); return CAST_INT(JsonParseError::TYPE_ERROR); } private: - static bool CheckType(const nlohmann::json &jsonObject, std::string &value) + static bool CheckType(cJSON *jsonObject, std::string &value) { - return jsonObject.is_string(); + if (jsonObject && cJSON_IsString(jsonObject)) { + char *valueStr = cJSON_GetStringValue(jsonObject); + if (valueStr) { + value = std::string(valueStr); + free(valueStr); + } + return true; + } + return false; } - static bool CheckType(const nlohmann::json &jsonObject, int32_t &value) + static bool CheckType(cJSON *jsonObject, int32_t &value) { - return jsonObject.is_number(); + if (jsonObject && cJSON_IsNumber(jsonObject)) { + value = cJSON_GetNumberValue(jsonObject); + return true; + } + return false; } - static bool CheckType(const nlohmann::json &jsonObject, uint32_t &value) + static bool CheckType(cJSON *jsonObject, uint32_t &value) { - return jsonObject.is_number(); + if (jsonObject && cJSON_IsNumber(jsonObject) && jsonObject->valuedouble >= 0) { + value = static_cast(jsonObject->valuedouble); + return true; + } + return false; } - static bool CheckType(const nlohmann::json &jsonObject, uint64_t &value) + static bool CheckType(cJSON *jsonObject, uint64_t &value) { - return jsonObject.is_number(); + if (jsonObject && cJSON_IsNumber(jsonObject) && jsonObject->valuedouble >= 0) { + value = value = static_cast(jsonObject->valuedouble); + return true; + } + return false; } - static bool CheckType(const nlohmann::json &jsonObject, int64_t &value) + static bool CheckType(cJSON *jsonObject, int64_t &value) { - return jsonObject.is_number(); + if (jsonObject && cJSON_IsNumber(jsonObject)) { + value = jsonObject->valuedouble; + return true; + } + return false; } - static bool CheckType(const nlohmann::json &jsonObject, double &value) + static bool CheckType(cJSON *jsonObject, double &value) { - return jsonObject.is_number(); + if (jsonObject && cJSON_IsNumber(jsonObject)) { + value = jsonObject->valuedouble; + return true; + } + return false; } - static bool CheckType(const nlohmann::json &jsonObject, bool &value) + static bool CheckType(cJSON *jsonObject, bool &value) { - return jsonObject.is_boolean(); + if (jsonObject && (cJSON_IsTrue(jsonObject) || cJSON_IsFalse(jsonObject))) { + value = cJSON_IsTrue(jsonObject) ? true : false; + return true; + } + return false; } - template static bool CheckType(const nlohmann::json &jsonObject, T &value) + template static bool CheckType(cJSON *jsonObject, T &value) { - return jsonObject.is_object(); + return cJSON_IsObject(jsonObject); } - template static bool CheckType(const nlohmann::json &jsonObject, std::vector &value) + template static bool CheckType(cJSON *jsonObject, std::vector &value) { - return jsonObject.is_array(); + return cJSON_IsArray(jsonObject); } - template static void GetValue(const nlohmann::json &jsonObject, const std::string &key, T &value) + + template static bool GetValue(cJSON *jsonObject, const std::string &key, T &value) { - jsonObject.at(key).get_to(value); + cJSON *item = cJSON_GetObjectItemCaseSensitive(jsonObject, key.c_str()); + if (!item) { + return false; + } + + if constexpr (std::is_same_v) + { + if (cJSON_IsNumber(item)) { + value = item->valueint; + } + } + else if constexpr (std::is_same_v) + { + if (cJSON_IsNumber(item)) { + value = item->valuedouble; + } + } + else if constexpr (std::is_same_v) + { + if (cJSON_IsTrue(item)) { + value = true; + } else if (cJSON_IsFalse(item)) { + value = false; + } + } else if constexpr (std::is_same_v) { + if (cJSON_IsString(item)) { + value = item->valuestring; + } + } else { + return false; + } + return true; } - static void GetValue(const nlohmann::json &jsonObject, const std::string &key, std::vector &value) + static void GetValue(cJSON *jsonObject, const std::string &key, std::vector &value) { if (!IsArray(jsonObject, key)) { return; } - nlohmann::json jsonArray = jsonObject.at(key); - for (nlohmann::json::iterator it = jsonArray.begin(); it != jsonArray.end(); ++it) { - if (!it.value().is_string()) { - continue; + cJSON *jsonArray = cJSON_GetObjectItemCaseSensitive(jsonObject, key.c_str()); + if (jsonArray == nullptr) { + return; + } + cJSON *currentItem = jsonArray->child; + while (currentItem != nullptr) { + if (cJSON_IsString(currentItem)) { + value.emplace_back(std::string(currentItem->valuestring)); } - value.push_back(static_cast(it.value())); + currentItem = currentItem->next; } } + }; } // namespace OHOS::UpdateService #endif // JSON_UTILS_H \ No newline at end of file diff --git a/foundations/ability/utils/utils.gni b/foundations/ability/utils/utils.gni index b4a33b7d..8c6c450b 100644 --- a/foundations/ability/utils/utils.gni +++ b/foundations/ability/utils/utils.gni @@ -13,7 +13,7 @@ import("//base/update/updateservice/updateengine.gni") -utils_external_deps = [ "json:nlohmann_json_static" ] +utils_external_deps = [] utils_deps = [] utils_include = [ "$updateengine_root_path/foundations/ability/utils/include" ] utils_src = [] diff --git a/foundations/model/include/business_error.h b/foundations/model/include/business_error.h index 05a2d988..10a3232d 100644 --- a/foundations/model/include/business_error.h +++ b/foundations/model/include/business_error.h @@ -20,8 +20,6 @@ #include #include -#include "nlohmann/json.hpp" - #include "call_result.h" #include "dupdate_json_utils.h" #include "error_message.h" @@ -50,22 +48,6 @@ struct BusinessError : public Parcelable { return *this; } - friend void to_json(nlohmann::json &jsonObj, const BusinessError &businessError) - { - jsonObj["message"] = businessError.message; - jsonObj["errorNum"] = businessError.errorNum; - jsonObj["data"] = businessError.data; - } - - friend void from_json(const nlohmann::json &jsonObj, BusinessError &businessError) - { - JsonUtils::GetValueAndSetTo(jsonObj, "message", businessError.message); - JsonUtils::GetValueAndSetTo(jsonObj, "data", businessError.data); - int32_t errorNumber = static_cast(CallResult::SUCCESS); - JsonUtils::GetValueAndSetTo(jsonObj, "errorNum", errorNumber); - businessError.errorNum = static_cast(errorNumber); - } - bool ReadFromParcel(Parcel &parcel); bool Marshalling(Parcel &parcel) const override; static BusinessError *Unmarshalling(Parcel &parcel); diff --git a/foundations/model/include/error_message.h b/foundations/model/include/error_message.h index 5cf71286..b9acfa76 100644 --- a/foundations/model/include/error_message.h +++ b/foundations/model/include/error_message.h @@ -19,8 +19,6 @@ #include #include -#include "nlohmann/json.hpp" - #include "dupdate_json_utils.h" #include "json_builder.h" @@ -31,18 +29,6 @@ struct ErrorMessage : public Parcelable { int32_t errorCode = 0; std::string errorMessage; - friend void to_json(nlohmann::json &jsonObj, const ErrorMessage &message) - { - jsonObj["errorCode"] = message.errorCode; - jsonObj["errorMessage"] = message.errorMessage; - } - - friend void from_json(const nlohmann::json &jsonObj, ErrorMessage &message) - { - JsonUtils::GetValueAndSetTo(jsonObj, "errorCode", message.errorCode); - JsonUtils::GetValueAndSetTo(jsonObj, "errorMessage", message.errorMessage); - } - JsonBuilder GetJsonBuilder() { return JsonBuilder() diff --git a/frameworks/js/napi/update/BUILD.gn b/frameworks/js/napi/update/BUILD.gn index 83dd6bfe..f5f0e9a4 100644 --- a/frameworks/js/napi/update/BUILD.gn +++ b/frameworks/js/napi/update/BUILD.gn @@ -50,9 +50,9 @@ ohos_shared_library("$updateengine_client_library_name") { "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", "c_utils:utils", # sptr + "cJSON:cjson", "hilog:libhilog", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", ] diff --git a/interfaces/inner_api/engine/BUILD.gn b/interfaces/inner_api/engine/BUILD.gn index d289aa10..f650da18 100644 --- a/interfaces/inner_api/engine/BUILD.gn +++ b/interfaces/inner_api/engine/BUILD.gn @@ -86,9 +86,9 @@ ohos_shared_library("$updateengine_inner_library_name") { external_deps = [ "bounds_checking_function:libsec_static", "c_utils:utils", # sptr + "cJSON:cjson", "hilog:libhilog", "ipc:ipc_core", - "json:nlohmann_json_static", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] diff --git a/services/core/ability/adapter/src/config_parse.cpp b/services/core/ability/adapter/src/config_parse.cpp index 7dc800ae..712f8d50 100644 --- a/services/core/ability/adapter/src/config_parse.cpp +++ b/services/core/ability/adapter/src/config_parse.cpp @@ -63,8 +63,8 @@ void ConfigParse::LoadConfigInfo() std::string rawJson(streambuffer.str()); readFile.close(); - nlohmann::json root = nlohmann::json::parse(rawJson, nullptr, false); - if (root.is_discarded()) { + cJSON *root = cJSON_Parse(rawJson.c_str()); + if (!root) { ENGINE_LOGE("json Create error!"); return; } @@ -72,6 +72,7 @@ void ConfigParse::LoadConfigInfo() JsonUtils::GetValueAndSetTo(root, "abInstallTimeout", configInfo_.abInstallTimeout); JsonUtils::GetValueAndSetTo(root, "streamInstallTimeout", configInfo_.streamInstallTimeout); JsonUtils::GetValueAndSetTo(root, "moduleLibPath", configInfo_.moduleLibPath); + cJSON_Delete(root); } } // namespace UpdateService } // namespace OHOS diff --git a/services/core/ability/model/include/device_info.h b/services/core/ability/model/include/device_info.h index ea146030..67b2a550 100644 --- a/services/core/ability/model/include/device_info.h +++ b/services/core/ability/model/include/device_info.h @@ -18,8 +18,6 @@ #include -#include "nlohmann/json.hpp" - #include "anonymous_utils.h" namespace OHOS { @@ -28,14 +26,6 @@ struct DeviceInfo { public: std::string udid; std::string deviceId; - - nlohmann::ordered_json ToJson(bool isPrint) - { - nlohmann::ordered_json json = nlohmann::ordered_json::object(); - json["udid"] = isPrint ? AnonymousUtils::AnonymousString(udid) : udid; - json["deviceId"] = isPrint ? AnonymousUtils::AnonymousString(deviceId) : deviceId; - return json; - } }; } // namespace UpdateService } // namespace OHOS diff --git a/services/engine/engine_sa.gni b/services/engine/engine_sa.gni index 74a5bb23..c32c2dba 100644 --- a/services/engine/engine_sa.gni +++ b/services/engine/engine_sa.gni @@ -138,7 +138,6 @@ sa_external_deps = [ "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "libxml2:libxml2", "mbedtls:mbedtls_shared", "openssl:libcrypto_shared", diff --git a/services/engine/include/update_service_impl_manager.h b/services/engine/include/update_service_impl_manager.h index 4827ed13..256cacf0 100644 --- a/services/engine/include/update_service_impl_manager.h +++ b/services/engine/include/update_service_impl_manager.h @@ -18,6 +18,7 @@ #include "iservice_online_updater.h" +#include #include #include "upgrade_info.h" diff --git a/services/firmware/check/include/firmware_icheck.h b/services/firmware/check/include/firmware_icheck.h index 0f4041e8..0cadca3c 100644 --- a/services/firmware/check/include/firmware_icheck.h +++ b/services/firmware/check/include/firmware_icheck.h @@ -22,7 +22,6 @@ #include #include "cJSON.h" -#include "nlohmann/json.hpp" #include "openssl/err.h" #include "openssl/ssl.h" #include "parameter.h" @@ -107,10 +106,11 @@ public: if (response.status != static_cast(HttpConstant::SUCCESS) || response.content.empty()) { checkStatus = CheckStatus::CHECK_FAIL; } else { - nlohmann::json root = nlohmann::json::parse(response.content, nullptr, false); - if (!root.is_discarded()) { - FIRMWARE_LONG_LOGI("FirmwareCheck response: %{public}s", root.dump().c_str()); + cJSON *root = cJSON_Parse(response.content.c_str()); + if (!root) { + FIRMWARE_LONG_LOGI("FirmwareCheck response: %{public}s", response.content.c_str()); } + cJSON_Delete(root); FirmwareCheckAnalyzeUtils().DoAnalyze(response.content, checkResultList_, duration_, checkAndAuthInfo_); checkStatus = CheckStatus::CHECK_SUCCESS; } diff --git a/services/firmware/common/include/firmware_common.h b/services/firmware/common/include/firmware_common.h index ce001cec..3ac697f4 100644 --- a/services/firmware/common/include/firmware_common.h +++ b/services/firmware/common/include/firmware_common.h @@ -18,8 +18,6 @@ #include -#include "nlohmann/json.hpp" - #include "anonymous_utils.h" #include "constant.h" #include "firmware_component.h" @@ -76,14 +74,6 @@ public: std::string versionNumber; std::string displayVersionNumber; std::string versionPackageType; - - nlohmann::ordered_json ToCheckJson() - { - nlohmann::ordered_json json = nlohmann::ordered_json::object(); - json["versionPackageType"] = versionPackageType; - json["versionNumber"] = versionNumber; - return json; - } }; enum VersionIndex { @@ -101,15 +91,6 @@ struct UpdatePackage { std::string versionId; int32_t packageIndex = 0; PackageType versionPackageType = PackageType::DYNAMIC; - - nlohmann::ordered_json ToJson() - { - nlohmann::ordered_json json = nlohmann::ordered_json::object(); - json["versionId"] = versionId; - json["packageIndex"] = packageIndex; - json["versionPackageType"] = CAST_INT(versionPackageType); - return json; - } }; struct TargetBlComponent { diff --git a/services/firmware/common/include/firmware_update_helper.h b/services/firmware/common/include/firmware_update_helper.h index 25456244..3d4d3f82 100644 --- a/services/firmware/common/include/firmware_update_helper.h +++ b/services/firmware/common/include/firmware_update_helper.h @@ -18,8 +18,6 @@ #include -#include "nlohmann/json.hpp" - #include "current_version_info.h" #include "firmware_changelog_utils.h" #include "firmware_constant.h" diff --git a/services/firmware/utils/include/firmware_check_analyze_utils.h b/services/firmware/utils/include/firmware_check_analyze_utils.h index 40005a70..16700f49 100644 --- a/services/firmware/utils/include/firmware_check_analyze_utils.h +++ b/services/firmware/utils/include/firmware_check_analyze_utils.h @@ -35,10 +35,10 @@ public: private: bool IsLegalStatus(int32_t status); - int32_t AnalyzeComponents(nlohmann::json &root); - int32_t ProcessCheckResults(const nlohmann::json &checkResults); - int32_t ProcessDescriptInfo(const nlohmann::json &descriptInfo); - int32_t AnalyzeBlVersionCheckResults(nlohmann::json &root, BlCheckResponse &response); + int32_t AnalyzeComponents(cJSON *root); + int32_t ProcessCheckResults(cJSON *checkResults); + int32_t ProcessDescriptInfo(cJSON *descriptInfo); + int32_t AnalyzeBlVersionCheckResults(cJSON *root, BlCheckResponse &response); private: std::vector components_; diff --git a/services/firmware/utils/src/firmware_check_analyze_utils.cpp b/services/firmware/utils/src/firmware_check_analyze_utils.cpp index 1c5099ac..bc188faf 100644 --- a/services/firmware/utils/src/firmware_check_analyze_utils.cpp +++ b/services/firmware/utils/src/firmware_check_analyze_utils.cpp @@ -37,8 +37,8 @@ void FirmwareCheckAnalyzeUtils::DoAnalyze(const std::string &rawJson, std::vecto { BlCheckResponse response; int32_t ret = CAST_INT(JsonParseError::ERR_OK); - nlohmann::json root; - if (!JsonUtils::ParseAndGetJsonObject(rawJson, root)) { + cJSON *root = JsonUtils::ParseAndGetJsonObject(rawJson); + if (!root) { FIRMWARE_LOGE("fail to parse out a json object"); return; } @@ -49,6 +49,7 @@ void FirmwareCheckAnalyzeUtils::DoAnalyze(const std::string &rawJson, std::vecto checkAndAuthInfo.responseStatus = std::to_string(status); if (!IsLegalStatus(status)) { FIRMWARE_LOGI("not found new version!"); + cJSON_Delete(root); return; } if (status == CAST_INT(CheckResultStatus::STATUS_NEW_VERSION_AVAILABLE)) { @@ -60,100 +61,118 @@ void FirmwareCheckAnalyzeUtils::DoAnalyze(const std::string &rawJson, std::vecto if (ret == CAST_INT(JsonParseError::ERR_OK)) { components = components_; } + cJSON_Delete(root); } -int32_t FirmwareCheckAnalyzeUtils::AnalyzeBlVersionCheckResults(nlohmann::json &root, BlCheckResponse &response) +int32_t FirmwareCheckAnalyzeUtils::AnalyzeBlVersionCheckResults(cJSON *root, BlCheckResponse &response) { - if (root.find("checkResults") == root.end()) { + cJSON *itemCheckResults = cJSON_GetObjectItemCaseSensitive(root, "checkResults"); + if (!itemCheckResults) { FIRMWARE_LOGE("FirmwareCheckAnalyzeUtils::AnalyzeBlVersionCheckResults no key checkResults"); return CAST_INT(JsonParseError::MISSING_PROP); } - FIRMWARE_LOGI("checkResults size is %{public}" PRIu64 "", static_cast(root["checkResults"].size())); + + FIRMWARE_LOGI("checkResults size is %{public}" PRIu64 "", + static_cast(cJSON_IsArray(itemCheckResults) ? cJSON_GetArraySize(itemCheckResults) : 0)); + int32_t ret = CAST_INT(JsonParseError::ERR_OK); - for (auto &result : root["checkResults"]) { - int32_t status = CAST_INT(CheckResultStatus::STATUS_SYSTEM_ERROR); - JsonUtils::GetValueAndSetTo(root, "searchStatus", status); - if (status == CAST_INT(CheckResultStatus::STATUS_NEW_VERSION_AVAILABLE)) { + int32_t status = CAST_INT(CheckResultStatus::STATUS_SYSTEM_ERROR); + JsonUtils::GetValueAndSetTo(root, "searchStatus", status); + if (status == CAST_INT(CheckResultStatus::STATUS_NEW_VERSION_AVAILABLE)) + { + for (int i = 0; i < cJSON_GetArraySize(itemCheckResults); i++) + { + cJSON *item = cJSON_GetArrayItem(itemCheckResults, i); BlVersionCheckResult checkResult; - ret += JsonUtils::GetValueAndSetTo(result, "descriptPackageId", checkResult.descriptPackageId); + ret += JsonUtils::GetValueAndSetTo(item, "descriptPackageId", checkResult.descriptPackageId); checkResult.blVersionType = 1; checkResult.status = std::to_string(status); UpdatePackage package; package.versionId = "1"; int32_t versionPackageType = CAST_INT(PackageType::DYNAMIC); - ret += JsonUtils::GetValueAndSetTo(result, "packageType", versionPackageType); + ret += JsonUtils::GetValueAndSetTo(item, "packageType", versionPackageType); package.versionPackageType = static_cast(versionPackageType); package.packageIndex = 0; checkResult.updatePackages.push_back(package); TargetBlComponent component; component.versionPackageType = package.versionPackageType; - ret += JsonUtils::GetValueAndSetTo(result, "versionName", component.displayVersionNumber); - ret += JsonUtils::GetValueAndSetTo(result, "versionName", component.versionNumber); + ret += JsonUtils::GetValueAndSetTo(item, "versionName", component.displayVersionNumber); + ret += JsonUtils::GetValueAndSetTo(item, "versionName", component.versionNumber); checkResult.targetBlComponents.push_back(component); - checkResult.blVersionInfo = result["blVersionInfo"].dump(); + JsonUtils::GetValueAndSetTo(item, "blVersionInfo", checkResult.blVersionInfo); response.blVersionCheckResults.push_back(checkResult); Version version; version.versionId = "1"; - ret += JsonUtils::GetValueAndSetTo(result, "versionCode", version.versionNumber); - ret += JsonUtils::GetValueAndSetTo(result, "url", version.url); + ret += JsonUtils::GetValueAndSetTo(item, "versionCode", version.versionNumber); + ret += JsonUtils::GetValueAndSetTo(item, "url", version.url); response.versionList.push_back(version); } } return ret; } -int32_t FirmwareCheckAnalyzeUtils::AnalyzeComponents(nlohmann::json &root) +int32_t FirmwareCheckAnalyzeUtils::AnalyzeComponents(cJSON *root) { // 检查 "checkResults" 是否存在 - if (root.find("checkResults") == root.end()) { + cJSON *itemCheckResults = cJSON_GetObjectItemCaseSensitive(root, "checkResults"); + if (!itemCheckResults) { FIRMWARE_LOGE("FirmwareCheckAnalyzeUtils::AnalyzeComponents no key checkResults"); return CAST_INT(JsonParseError::MISSING_PROP); } - FIRMWARE_LOGI("checkResults size is %{public}" PRIu64 "", static_cast(root["checkResults"].size())); + FIRMWARE_LOGI("checkResults size is %{public}" PRIu64 "", + static_cast(cJSON_IsArray(itemCheckResults) ? cJSON_GetArraySize(itemCheckResults) : 0)); // 初始化返回值 int32_t ret = CAST_INT(JsonParseError::ERR_OK); // 处理 "checkResults" 部分 - ret += ProcessCheckResults(root["checkResults"]); + ret += ProcessCheckResults(itemCheckResults); // 检查 "descriptInfo" 是否存在 - if (root.find("descriptInfo") == root.end()) { - FIRMWARE_LOGE("FirmwareCheckAnalyzeUtils::AnalyzeComponents no key descriptInfo"); + cJSON *itemDescriptInfo = cJSON_GetObjectItemCaseSensitive(root, "descriptInfo"); + if (!itemDescriptInfo) { + FIRMWARE_LOGE("FirmwareCheckAnalyzeUtils::AnalyzeComponents no key descriptInfo"); return CAST_INT(JsonParseError::MISSING_PROP); } // 处理 "descriptInfo" 部分 - ret += ProcessDescriptInfo(root["descriptInfo"]); + ret += ProcessDescriptInfo(itemDescriptInfo); return ret; } -int32_t FirmwareCheckAnalyzeUtils::ProcessCheckResults(const nlohmann::json &checkResults) +int32_t FirmwareCheckAnalyzeUtils::ProcessCheckResults(cJSON *checkResults) { int32_t ret = CAST_INT(JsonParseError::ERR_OK); std::string componentId; - for (auto &result : checkResults) { + if (!checkResults) { + FIRMWARE_LOGE("AnalyzeComponents no key checkResults"); + return CAST_INT(JsonParseError::MISSING_PROP); + } + + for (int i = 0; i < cJSON_GetArraySize(checkResults); i++) { + cJSON *itemResult = cJSON_GetArrayItem(checkResults, i); + FirmwareComponent component; int32_t componetSize = 0; // 获取组件相关属性 - ret += JsonUtils::GetValueAndSetTo(result, "descriptPackageId", component.descriptPackageId); - ret += JsonUtils::GetValueAndSetTo(result, "url", component.url); - ret += JsonUtils::GetValueAndSetTo(result, "size", componetSize); + ret += JsonUtils::GetValueAndSetTo(itemResult, "descriptPackageId", component.descriptPackageId); + ret += JsonUtils::GetValueAndSetTo(itemResult, "url", component.url); + ret += JsonUtils::GetValueAndSetTo(itemResult, "size", componetSize); component.size = static_cast(componetSize); component.fileName = StringUtils::GetLastSplitString(component.url, "/"); - ret += JsonUtils::GetValueAndSetTo(result, "verifyInfo", component.verifyInfo); - ret += JsonUtils::GetValueAndSetTo(result, "versionCode", component.versionNumber); - ret += JsonUtils::GetValueAndSetTo(result, "versionName", component.targetBlVersionNumber); + ret += JsonUtils::GetValueAndSetTo(itemResult, "verifyInfo", component.verifyInfo); + ret += JsonUtils::GetValueAndSetTo(itemResult, "versionCode", component.versionNumber); + ret += JsonUtils::GetValueAndSetTo(itemResult, "versionName", component.targetBlVersionNumber); int32_t versionPackageType = CAST_INT(PackageType::DYNAMIC); - ret += JsonUtils::GetValueAndSetTo(result, "packageType", versionPackageType); + ret += JsonUtils::GetValueAndSetTo(itemResult, "packageType", versionPackageType); component.versionPackageType = static_cast(versionPackageType); int32_t otaType = CAST_INT(OtaType::REGULAR); - ret += JsonUtils::GetValueAndSetTo(result, "otaType", otaType); + ret += JsonUtils::GetValueAndSetTo(itemResult, "otaType", otaType); component.otaType = static_cast(otaType); component.targetBlDisplayVersionNumber = component.targetBlVersionNumber; @@ -163,23 +182,28 @@ int32_t FirmwareCheckAnalyzeUtils::ProcessCheckResults(const nlohmann::json &che components_.push_back(component); } - return ret; } -int32_t FirmwareCheckAnalyzeUtils::ProcessDescriptInfo(const nlohmann::json &descriptInfo) +int32_t FirmwareCheckAnalyzeUtils::ProcessDescriptInfo(cJSON *descriptInfo) { int32_t ret = CAST_INT(JsonParseError::ERR_OK); std::string componentId = components_.empty() ? "" : components_.back().descriptPackageId; - for (auto &info : descriptInfo) { + if (!descriptInfo) { + FIRMWARE_LOGE("ProcessDescriptInfo no descriptInfo"); + return CAST_INT(JsonParseError::MISSING_PROP); + } + + for (int i = 0; i < cJSON_GetArraySize(descriptInfo); i++) { + cJSON *itemInfo = cJSON_GetArrayItem(descriptInfo, i); int32_t descriptInfoType; std::string descContent; std::string subString = "quota"; std::string replString = "\""; - ret += JsonUtils::GetValueAndSetTo(info, "descriptionType", descriptInfoType); - ret += JsonUtils::GetValueAndSetTo(info, "content", descContent); + ret += JsonUtils::GetValueAndSetTo(itemInfo, "descriptionType", descriptInfoType); + ret += JsonUtils::GetValueAndSetTo(itemInfo, "content", descContent); StringUtils::ReplaceStringAll(descContent, subString, replString); diff --git a/services/startup/manage/include/schedule_config.h b/services/startup/manage/include/schedule_config.h index 5a4e9bb3..23ef1c73 100644 --- a/services/startup/manage/include/schedule_config.h +++ b/services/startup/manage/include/schedule_config.h @@ -28,7 +28,7 @@ public: static uint64_t GetIdleCheckInterval(); private: - static uint64_t ParseConfig(nlohmann::json &root, const std::string &key, uint64_t defaultValue); + static uint64_t ParseConfig(cJSON *root, const std::string &key, uint64_t defaultValue); private: static uint64_t pullupInterval_; diff --git a/services/startup/manage/src/schedule_config.cpp b/services/startup/manage/src/schedule_config.cpp index 2a1c1789..29750d85 100644 --- a/services/startup/manage/src/schedule_config.cpp +++ b/services/startup/manage/src/schedule_config.cpp @@ -27,9 +27,8 @@ uint64_t ScheduleConfig::idleCheckInterval_ = Startup::IDLE_CHECK_INTERVAL; void ScheduleConfig::InitConfig() { ENGINE_LOGI("InitConfig"); - nlohmann::json root = - nlohmann::json::parse(FileUtils::ReadDataFromFile(Constant::DUPDATE_ENGINE_CONFIG_PATH), nullptr, false); - if (root.is_discarded()) { + cJSON* root = cJSON_Parse(FileUtils::ReadDataFromFile(Constant::DUPDATE_ENGINE_CONFIG_PATH).c_str()); + if (!root) { ENGINE_LOGI("InitConfig load fail"); return; } @@ -37,6 +36,7 @@ void ScheduleConfig::InitConfig() idleCheckInterval_ = ParseConfig(root, Startup::IDLE_CHECK_INTERVAL_CONFIG, Startup::IDLE_CHECK_INTERVAL); ENGINE_LOGI("InitConfig pullupInterval: %{public}s, idleCheckInterval: %{public}s", std::to_string(pullupInterval_).c_str(), std::to_string(idleCheckInterval_).c_str()); + cJSON_Delete(root); } uint64_t ScheduleConfig::GetPullupInterval() @@ -49,7 +49,7 @@ uint64_t ScheduleConfig::GetIdleCheckInterval() return idleCheckInterval_; } -uint64_t ScheduleConfig::ParseConfig(nlohmann::json &root, const std::string &key, uint64_t defaultValue) +uint64_t ScheduleConfig::ParseConfig(cJSON *root, const std::string &key, uint64_t defaultValue) { uint64_t value = 0; int32_t ret = JsonUtils::GetValueAndSetTo(root, key, value); -- Gitee From e47a80b30dbe15d3cb86b7c454126df5a8e149ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Wed, 14 May 2025 21:11:13 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9cJSON=20Signed-off-by:=20?= =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/include/dupdate_json_utils.h | 229 ++++-------------- 1 file changed, 49 insertions(+), 180 deletions(-) diff --git a/foundations/ability/utils/include/dupdate_json_utils.h b/foundations/ability/utils/include/dupdate_json_utils.h index fd056e1f..004bf9bd 100644 --- a/foundations/ability/utils/include/dupdate_json_utils.h +++ b/foundations/ability/utils/include/dupdate_json_utils.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Huawei Device Co., Ltd. +* Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -38,18 +38,19 @@ class JsonUtils { public: template static int32_t GetValueAndSetTo(cJSON *jsonObject, const std::string &key, T &value) { - if (!cJSON_HasObjectItem(jsonObject, key.c_str())) - { + if (!jsonObject || key.empty()) { + return CAST_INT(JsonParseError::MISSING_PROP); + } + + cJSON *item = cJSON_GetObjectItemCaseSensitive(jsonObject, key.c_str()); + if (!item) { return CAST_INT(JsonParseError::MISSING_PROP); } - cJSON *item = cJSON_GetObjectItem(jsonObject, key.c_str()); - if (!CheckType(item, value)) - { + if (!CheckType(item, value)) { return CAST_INT(JsonParseError::TYPE_ERROR); } - - GetValue(item, key, value); + GetValue(item, value); return CAST_INT(JsonParseError::ERR_OK); } @@ -85,198 +86,85 @@ public: return item; } - static int32_t GetValueAndSetToArray(cJSON *jsonObject, const std::string &key, cJSON **value) - { - if (!cJSON_HasObjectItem(jsonObject, key.c_str())) { - return CAST_INT(JsonParseError::MISSING_PROP); - } - - cJSON* item = cJSON_GetObjectItem(jsonObject, key.c_str()); - if (!cJSON_IsArray(item)) { - return CAST_INT(JsonParseError::TYPE_ERROR); - } - - *value = item; - return CAST_INT(JsonParseError::ERR_OK); - } - - static void SetJsonToVector(cJSON *jsonArray, std::vector &vector) - { - while (jsonArray != nullptr) { - if (cJSON_IsString(jsonArray)) { - vector.emplace_back(std::string(jsonArray->valuestring)); - } - jsonArray = jsonArray->next; - } - } - - static void SetJsonToVector(cJSON *jsonObject, const std::string &key, - std::vector &vector) - { - if (!IsArray(jsonObject, key)) { - return; - } - - cJSON *root = cJSON_GetObjectItemCaseSensitive(jsonObject, key.c_str()); - if (root == nullptr) { - return; - } - cJSON *jsonArray = root->child; - if (jsonArray == nullptr) { - return; - } - - SetJsonToVector(jsonArray, vector); - } - - static bool IsArray(cJSON *jsonObject, const std::string &key) - { - cJSON *item = cJSON_GetObjectItemCaseSensitive(jsonObject, key.c_str()); - return item && cJSON_IsArray(item); - } - - template void T(cJSON *root, const T &value) - { - return; - } - - template static std::string StructToJsonStr(const T &value) - { - cJSON *root = cJSON_CreateObject(); - T(root, value); // 需针对不同类型特化实现 - char *jsonStr = cJSON_Print(root); - std::string result(jsonStr); - cJSON_Delete(root); - free(jsonStr); - return result; - } - - template static int32_t JsonStrToStruct(const std::string &jsonStr, T &value) - { - if (jsonStr.empty()) { - return CAST_INT(JsonParseError::COMMOM_ERROR); - } - - cJSON *jsonObj = cJSON_Parse(jsonStr.c_str()); - if (!jsonObj) - { - return CAST_INT(JsonParseError::COMMOM_ERROR); - } - - if (CheckType(jsonObj, value)) - { - value = T(jsonObj); // 需针对不同类型特化实现 - cJSON_Delete(jsonObj); - return CAST_INT(JsonParseError::ERR_OK); - } - - cJSON_Delete(jsonObj); - return CAST_INT(JsonParseError::TYPE_ERROR); - } - private: static bool CheckType(cJSON *jsonObject, std::string &value) { - if (jsonObject && cJSON_IsString(jsonObject)) { - char *valueStr = cJSON_GetStringValue(jsonObject); - if (valueStr) { - value = std::string(valueStr); - free(valueStr); - } - return true; - } - return false; + return jsonObject && cJSON_IsString(jsonObject); } static bool CheckType(cJSON *jsonObject, int32_t &value) { - if (jsonObject && cJSON_IsNumber(jsonObject)) { - value = cJSON_GetNumberValue(jsonObject); - return true; - } - return false; + return jsonObject && cJSON_IsNumber(jsonObject); } - static bool CheckType(cJSON *jsonObject, uint32_t &value) - { - if (jsonObject && cJSON_IsNumber(jsonObject) && jsonObject->valuedouble >= 0) { - value = static_cast(jsonObject->valuedouble); - return true; - } - return false; - } - - static bool CheckType(cJSON *jsonObject, uint64_t &value) + static bool CheckType(cJSON *jsonObject, int64_t &value) { - if (jsonObject && cJSON_IsNumber(jsonObject) && jsonObject->valuedouble >= 0) { - value = value = static_cast(jsonObject->valuedouble); - return true; - } - return false; + return jsonObject && cJSON_IsNumber(jsonObject); } - static bool CheckType(cJSON *jsonObject, int64_t &value) + static bool CheckType(cJSON *jsonObject, uint32_t &value) { - if (jsonObject && cJSON_IsNumber(jsonObject)) { - value = jsonObject->valuedouble; - return true; - } - return false; + return jsonObject && cJSON_IsNumber(jsonObject) && jsonObject->valuedouble >=0; } - static bool CheckType(cJSON *jsonObject, double &value) + static bool CheckType(cJSON *jsonObject, uint64_t &value) { - if (jsonObject && cJSON_IsNumber(jsonObject)) { - value = jsonObject->valuedouble; - return true; - } - return false; + return jsonObject && cJSON_IsNumber(jsonObject) && jsonObject->valuedouble >=0; } - static bool CheckType(cJSON *jsonObject, bool &value) + static bool CheckType(cJSON *jsonObject, bool value) { - if (jsonObject && (cJSON_IsTrue(jsonObject) || cJSON_IsFalse(jsonObject))) { - value = cJSON_IsTrue(jsonObject) ? true : false; - return true; - } - return false; + return jsonObject && (jsonObject->type == cJSON_True || jsonObject->type == cJSON_False); } - template static bool CheckType(cJSON *jsonObject, T &value) + template + static bool CheckType(cJSON *jsonObject, T &value) { return cJSON_IsObject(jsonObject); } - template static bool CheckType(cJSON *jsonObject, std::vector &value) + template + static bool CheckType(cJSON *jsonObject, std::vector &value) { return cJSON_IsArray(jsonObject); } - - template static bool GetValue(cJSON *jsonObject, const std::string &key, T &value) + // string vector + static void GetValue(const cJSON *jsonArray, std::vector &value) { - cJSON *item = cJSON_GetObjectItemCaseSensitive(jsonObject, key.c_str()); - if (!item) { - return false; + if (!jsonArray || !cJSON_IsArray(jsonArray)) { + return; } - if constexpr (std::is_same_v) - { + const cJSON *element = nullptr; + cJSON_ArrayForEach(element, jsonArray) { + if (cJSON_IsString(element) && element->valuestring != nullptr) { + value.push_back(element->valuestring); + } + } + } + + // int ,double + template + static void GetValue(cJSON *item, T &value) + { + printf("GetValue: 1111\n"); + if constexpr (std::is_same_v || std::is_same_v) { if (cJSON_IsNumber(item)) { value = item->valueint; + } else { + return; } - } - else if constexpr (std::is_same_v) - { + } else if constexpr (std::is_same_v || std::is_same_v) { if (cJSON_IsNumber(item)) { value = item->valuedouble; + } else { + return; } - } - else if constexpr (std::is_same_v) - { + } else if constexpr (std::is_same_v) { if (cJSON_IsTrue(item)) { value = true; - } else if (cJSON_IsFalse(item)) { + } else { value = false; } } else if constexpr (std::is_same_v) { @@ -284,29 +172,10 @@ private: value = item->valuestring; } } else { - return false; - } - return true; - } - - static void GetValue(cJSON *jsonObject, const std::string &key, std::vector &value) - { - if (!IsArray(jsonObject, key)) { - return; - } - cJSON *jsonArray = cJSON_GetObjectItemCaseSensitive(jsonObject, key.c_str()); - if (jsonArray == nullptr) { return; } - cJSON *currentItem = jsonArray->child; - while (currentItem != nullptr) { - if (cJSON_IsString(currentItem)) { - value.emplace_back(std::string(currentItem->valuestring)); - } - currentItem = currentItem->next; - } } }; } // namespace OHOS::UpdateService -#endif // JSON_UTILS_H \ No newline at end of file +#endif // JSON_UTILS_H -- Gitee From 6d94c6a2b23db29e89dd97dfb12be8740c910504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=8F=8B=E6=9D=BE?= Date: Thu, 15 May 2025 07:59:19 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9uint64=5Ft=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邹友松 --- .../utils/include/dupdate_json_utils.h | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/foundations/ability/utils/include/dupdate_json_utils.h b/foundations/ability/utils/include/dupdate_json_utils.h index 004bf9bd..f9db7129 100644 --- a/foundations/ability/utils/include/dupdate_json_utils.h +++ b/foundations/ability/utils/include/dupdate_json_utils.h @@ -40,7 +40,7 @@ public: { if (!jsonObject || key.empty()) { return CAST_INT(JsonParseError::MISSING_PROP); - } + } cJSON *item = cJSON_GetObjectItemCaseSensitive(jsonObject, key.c_str()); if (!item) { @@ -94,12 +94,12 @@ private: static bool CheckType(cJSON *jsonObject, int32_t &value) { - return jsonObject && cJSON_IsNumber(jsonObject); + return jsonObject && cJSON_IsNumber(jsonObject); } static bool CheckType(cJSON *jsonObject, int64_t &value) { - return jsonObject && cJSON_IsNumber(jsonObject); + return jsonObject && cJSON_IsNumber(jsonObject); } static bool CheckType(cJSON *jsonObject, uint32_t &value) @@ -129,7 +129,6 @@ private: return cJSON_IsArray(jsonObject); } - // string vector static void GetValue(const cJSON *jsonArray, std::vector &value) { if (!jsonArray || !cJSON_IsArray(jsonArray)) { @@ -143,23 +142,21 @@ private: } } } - - // int ,double + template static void GetValue(cJSON *item, T &value) { - printf("GetValue: 1111\n"); if constexpr (std::is_same_v || std::is_same_v) { if (cJSON_IsNumber(item)) { value = item->valueint; - } else { - return; } } else if constexpr (std::is_same_v || std::is_same_v) { if (cJSON_IsNumber(item)) { value = item->valuedouble; - } else { - return; + } + } else if constexpr (std::is_same_v || std::is_same_v) { + if (cJSON_IsNumber(item)) { + value = item->valuedouble; } } else if constexpr (std::is_same_v) { if (cJSON_IsTrue(item)) { @@ -174,8 +171,8 @@ private: } else { return; } + return; } - }; } // namespace OHOS::UpdateService #endif // JSON_UTILS_H -- Gitee