diff --git a/interfaces/inner_api/appexecfwk_core/src/quick_fix/quick_fix_result_info.cpp b/interfaces/inner_api/appexecfwk_core/src/quick_fix/quick_fix_result_info.cpp index cc06f686055d59ef9e6305555d3ca6431471de2e..0546c59133cb5f0c779880224ae05dfe5d6609d1 100755 --- a/interfaces/inner_api/appexecfwk_core/src/quick_fix/quick_fix_result_info.cpp +++ b/interfaces/inner_api/appexecfwk_core/src/quick_fix/quick_fix_result_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -16,7 +16,7 @@ #include "app_log_tag_wrapper.h" #include "app_log_wrapper.h" #include "bundle_constants.h" -#include "nlohmann/json.hpp" +#include "json_util.h" #include "parcel_macro.h" #include "quick_fix_result_info.h" @@ -76,16 +76,24 @@ DeployQuickFixResult *DeployQuickFixResult::Unmarshalling(Parcel &parcel) std::string DeployQuickFixResult::ToString() const { - nlohmann::json deployResultJson = nlohmann::json { - { QUICK_FIX_RESULT_CODE, resultCode }, - { QUICK_FIX_BUNDLE_NAME, bundleName }, - { QUICK_FIX_BUNDLE_VERSION_CODE, bundleVersionCode }, - { QUICK_FIX_PATCH_VERSION_CODE, patchVersionCode }, - { QUICK_FIX_IS_SO_CONTAINED, isSoContained }, - { QUICK_FIX_TYPE, static_cast(type) }, - { QUICK_FIX_MODULE_NAME, moduleNames } - }; - return deployResultJson.dump(Constants::DUMP_INDENT); + cJSON* jsonObject = cJSON_CreateObject(); + if (!jsonObject || !cJSON_IsObject(jsonObject)) { + APP_LOGE("Invalid JSON object"); + return ""; + } + cJSON_AddNumberToObject(jsonObject, QUICK_FIX_RESULT_CODE, resultCode); + cJSON_AddStringToObject(jsonObject, QUICK_FIX_BUNDLE_NAME, bundleName.c_str()); + cJSON_AddNumberToObject(jsonObject, QUICK_FIX_BUNDLE_VERSION_CODE, bundleVersionCode); + cJSON_AddNumberToObject(jsonObject, QUICK_FIX_PATCH_VERSION_CODE, patchVersionCode); + cJSON_AddBoolToObject(jsonObject, QUICK_FIX_IS_SO_CONTAINED, isSoContained); + cJSON_AddNumberToObject(jsonObject, QUICK_FIX_TYPE, static_cast(type)); + if (!CJsonAddArrayToObject, std::string>(jsonObject, QUICK_FIX_MODULE_NAME, + moduleNames, ArrayType::STRING)) { + APP_LOGE("add moduleNames to jsonObject failed"); + } + std::string result = BMSJsonUtil::GetJsonString(jsonObject, true); + cJSON_Delete(jsonObject); + return result; } void DeployQuickFixResult::SetResCode(int32_t resCode) @@ -125,11 +133,16 @@ SwitchQuickFixResult *SwitchQuickFixResult::Unmarshalling(Parcel &parcel) std::string SwitchQuickFixResult::ToString() const { - nlohmann::json switchResultJson = nlohmann::json { - { QUICK_FIX_RESULT_CODE, resultCode }, - { QUICK_FIX_BUNDLE_NAME, bundleName } - }; - return switchResultJson.dump(Constants::DUMP_INDENT); + cJSON* jsonObject = cJSON_CreateObject(); + if (!jsonObject || !cJSON_IsObject(jsonObject)) { + APP_LOGE("Invalid JSON object"); + return ""; + } + cJSON_AddNumberToObject(jsonObject, QUICK_FIX_RESULT_CODE, resultCode); + cJSON_AddStringToObject(jsonObject, QUICK_FIX_BUNDLE_NAME, bundleName.c_str()); + std::string result = BMSJsonUtil::GetJsonString(jsonObject, true); + cJSON_Delete(jsonObject); + return result; } int32_t SwitchQuickFixResult::GetResCode() @@ -169,11 +182,16 @@ DeleteQuickFixResult *DeleteQuickFixResult::Unmarshalling(Parcel &parcel) std::string DeleteQuickFixResult::ToString() const { - nlohmann::json deleteResultJson = nlohmann::json { - { QUICK_FIX_RESULT_CODE, resultCode }, - { QUICK_FIX_BUNDLE_NAME, bundleName } - }; - return deleteResultJson.dump(Constants::DUMP_INDENT); + cJSON* jsonObject = cJSON_CreateObject(); + if (!jsonObject || !cJSON_IsObject(jsonObject)) { + APP_LOGE("Invalid JSON object"); + return ""; + } + cJSON_AddNumberToObject(jsonObject, QUICK_FIX_RESULT_CODE, resultCode); + cJSON_AddStringToObject(jsonObject, QUICK_FIX_BUNDLE_NAME, bundleName.c_str()); + std::string result = BMSJsonUtil::GetJsonString(jsonObject, true); + cJSON_Delete(jsonObject); + return result; } int32_t DeleteQuickFixResult::GetResCode()