diff --git a/json_tool/gabs.go b/json_tool/gabs.go index e8ede3b..077b57f 100644 --- a/json_tool/gabs.go +++ b/json_tool/gabs.go @@ -129,7 +129,11 @@ func (df *DataFilter) UserItemToSlice() { // // Date : 2022/1/23 12:45 AM func (df *DataFilter) getValueType(valueResult gjson.Result) string { - dataType := reflect.TypeOf(valueResult.Value()).String() + dataTypeVal := reflect.TypeOf(valueResult.Value()) + if nil == dataTypeVal { + return "NIL" + } + dataType := dataTypeVal.String() if strings.Contains(dataType, "int") { return "int64" } @@ -243,7 +247,6 @@ func (df *DataFilter) getArrayData(source string, pathArr []string) []gjson.Resu resultList := make([]gjson.Result, 0) dataList := gjson.Get(source, pathArr[0]).Array() for idx := 0; idx < len(dataList); idx++ { - // sourceData := gjson.Get(source, dataList[idx].String()).String() resultList = append(resultList, df.getArrayData(dataList[idx].String(), pathArr[1:])...) } return resultList diff --git a/json_tool/json_test.go b/json_tool/json_test.go index e8cb6ef..b479147 100644 --- a/json_tool/json_test.go +++ b/json_tool/json_test.go @@ -267,7 +267,7 @@ func TestDataFilterDiffArr(t *testing.T) { rule := []*FilterDataRule{ // {SourceKey: "name", MapKey: "slice.[]", DefaultValue: "用户姓名默认值"}, {SourceKey: "table.[].user_list.[].name", MapKey: "user_list.[].detail.name", DefaultValue: "用户姓名默认值"}, - {SourceKey: "table.[].user_list.[].age", MapKey: "user_list.[]detail.age", DefaultValue: "用户姓名默认值"}, + {SourceKey: "table.[].user_list.[].age", MapKey: "user_list.[].detail.age", DefaultValue: "用户姓名默认值"}, } byteData, _ := json.Marshal(source) filter := NewDataFilter(string(byteData), rule)