save code

This commit is contained in:
2022-01-26 18:36:05 +08:00
parent 3047c60428
commit 632ef3ed7f
2 changed files with 13 additions and 9 deletions

View File

@ -8,6 +8,7 @@
package json_tool
import (
"encoding/json"
"fmt"
"reflect"
"strings"
@ -218,18 +219,21 @@ func (df *DataFilter) dealDiffArr(diffArr []string) {
// 没处理过, 开始处理
jsonResultList := df.getArrayData(df.source, diffArr)
fmt.Println(jsonResultList)
if len(jsonResultList) == 0 {
return
}
newDataList := gabs.New()
newPath := util.GenRandomString("", 8)
var result map[string]interface{}
_ = json.Unmarshal([]byte(df.source), &result)
JSONObject, _ := gabs.Consume(result)
_, _ = JSONObject.ArrayP(newPath)
for _, item := range jsonResultList {
newDataList.ArrayAppend(item.String())
if err := JSONObject.ArrayAppendP(item.Value(), newPath); nil != err {
fmt.Println(err.Error())
}
}
JSONObject, _ := gabs.Consume(df.source)
_, _ = JSONObject.SetP(newDataList.Data(), newPath)
fmt.Println(123, JSONObject.String())
df.source = JSONObject.String()
}
// getArrayData 获取数据