From aab78082ceddafa935589bb0b64d8b2cd3ee5c3d Mon Sep 17 00:00:00 2001 From: gaoda <2772718884@qq.com> Date: Wed, 12 Nov 2025 10:58:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor(common):=E4=BC=98=E5=8C=96JSON?= =?UTF-8?q?=E6=B8=85=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用gjson.DecodeToJson替代gjson.Unmarshal提高解析效率 - 添加StrNumber选项支持字符串数字处理 - 简化数据清理流程 - 移除不必要的中间变量声明 - 提升JSON解析的准确性和性能 --- lklsdk/common/json_cleaner.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lklsdk/common/json_cleaner.go b/lklsdk/common/json_cleaner.go index 63e6f33..e044f88 100644 --- a/lklsdk/common/json_cleaner.go +++ b/lklsdk/common/json_cleaner.go @@ -8,15 +8,14 @@ import ( // CleanJSON 清理JSON字符串中的空值和0值字段 func CleanJSON(jsonStr string) ([]byte, error) { - var data interface{} - - // 解析JSON字符串 - if err := gjson.Unmarshal([]byte(jsonStr), &data); err != nil { + // 解析为JSON + json, err := gjson.DecodeToJson(jsonStr, gjson.Options{StrNumber: true}) + if err != nil { return nil, err } // 递归清理数据 - cleaned := cleanData(data) + cleaned := cleanData(json) // 转换回JSON字符串 result, err := gjson.Marshal(cleaned)