sjson #1
31
filter.go
31
filter.go
@ -97,6 +97,10 @@ func (f *filter) IsArray(rule MapRule) bool {
|
||||
//
|
||||
// Date : 17:41 2023/1/1
|
||||
func (f *filter) handleArray(rule MapRule) error {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
|
||||
sourcePathArray := strings.Split(rule.SourcePath, "[]")
|
||||
mapPathArray := strings.Split(rule.MapPath, "[]")
|
||||
if len(sourcePathArray) != len(mapPathArray) {
|
||||
@ -104,21 +108,32 @@ func (f *filter) handleArray(rule MapRule) error {
|
||||
return errors.New("map rule is invalid")
|
||||
}
|
||||
// 提取某一个list下的字段, 组成一个list
|
||||
|
||||
res := make([]string, 0)
|
||||
f.getAllFinalData(res, gjson.Get(f.sourceData, sourcePathArray[0]).Array(), sourcePathArray[1:])
|
||||
if f.formatResult, err = sjson.Set(f.formatResult, mapPathArray[0], res); nil != err {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// getAllFinalData ...
|
||||
// extraFinalResult 提取全部最底层结果
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
// Author : zhangdeman001@ke.com<张德满>
|
||||
//
|
||||
// Date : 18:42 2023/1/1
|
||||
func (f *filter) getAllFinalData(pathArr []string) []string {
|
||||
res := make([]string, 0)
|
||||
|
||||
return res
|
||||
// Date : 14:00 2023/1/2
|
||||
func (f *filter) getAllFinalData(res []string, resultList []gjson.Result, pathArr []string) {
|
||||
if len(pathArr) == 0 {
|
||||
for _, item := range resultList {
|
||||
res = append(res, item.String())
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, item := range resultList {
|
||||
f.extraFinalResult(res, item.Array(), pathArr[1:])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// String 获取格式化之后的字符串
|
||||
|
Loading…
Reference in New Issue
Block a user