增加应用市场返回数据为空处理
authorCaisking <Casiking@zhihuishixun.com>
Wed, 28 May 2025 09:12:11 +0000 (17:12 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Wed, 28 May 2025 09:12:11 +0000 (17:12 +0800)
code/sdk/application/wearable/fd230/service/app_store/app_store.cpp

index 8fcc4e8..4570f1b 100644 (file)
@@ -206,25 +206,26 @@ cJSON* ble_get_pkg_list() {
     int32_t count = 0;
     char *jsonString;
     
+    // 2. 创建 JSON 数组
+    cJSON *jsonArray = cJSON_CreateArray();
+    if (jsonArray == nullptr) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "cJSON_CreateArray failed");
+        AdapterFree(bundleInfos);
+        return nullptr;
+    }
+
+
     // 1. 获取应用列表
     if (OHOS::BundleMsClient::GetInstance().GetBundleInfos(0, &bundleInfos, &count) != 0) {
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "Failed to get bundle infos");
-        return nullptr;
+        return jsonArray;
     }
     
     WEARABLE_LOGI(WEARABLE_LOG_MODULE_BLE, "Successfully retrieved %d bundle infos", count);
     if (count <= 0) {
         AdapterFree(bundleInfos);
         WEARABLE_LOGW(WEARABLE_LOG_MODULE_BLE, "No packages found");
-        return nullptr;
-    }
-
-    // 2. 创建 JSON 数组
-    cJSON *jsonArray = cJSON_CreateArray();
-    if (jsonArray == nullptr) {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_BLE, "cJSON_CreateArray failed");
-        AdapterFree(bundleInfos);
-        return nullptr;
+        return jsonArray;
     }
 
     // 3. 填充数组元素
@@ -271,9 +272,9 @@ cJSON* ble_get_pkg_list() {
     return jsonArray;
 
 CLEANUP:
-    cJSON_Delete(jsonArray);
+    // cJSON_Delete(jsonArray);
     AdapterFree(bundleInfos);
-    return nullptr;
+    return jsonArray;
 }
 //获取表端信息
 /**