From: Caisking <3449750381@qq.com> Date: Fri, 28 Jun 2024 05:09:13 +0000 (+0800) Subject: 补交 X-Git-Tag: release_V1.2.70_20241020_135402~934 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=79dc338297deca4f857ade4ab0dc3bb16de3e323;p=mirrors%2FFD230.git 补交 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp index e7e14402c..88e3c23e6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp @@ -1,12 +1,15 @@ #include "health_service.h" #include -#include #include "wearable_log.h" #include "cJSON.h" #include #include #include "kv_store.h" #include "custom_utils.h" +#include +#include +#include +#include namespace OHOS { @@ -112,24 +115,35 @@ namespace OHOS return false; } - std::string jsonDataString((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); + // 读取文件内容到字符串 + std::stringstream buffer; + buffer << inFile.rdbuf(); + std::string jsonDataString = buffer.str(); const char *jsonData = jsonDataString.c_str(); printf("jsonData:%s\r\n", jsonData); if (jsonDataString.empty()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " jsonDataString is error"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jsonDataString is empty"); + inFile.close(); + return false; + } + + cJSON *root = cJSON_Parse(jsonData); + if (root == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to parse JSON data"); inFile.close(); return false; } if (type == HEALTH_TYPE_HEART) { - heart_root = cJSON_Parse(jsonData); + heart_root = root; } - if (type == HEALTH_TYPE_OXYGEN) + else if (type == HEALTH_TYPE_OXYGEN) { - oxygen_root = cJSON_Parse(jsonData); + oxygen_root = root; } inFile.close();