引入复杂数据类型 & 支持是slice/map

This commit is contained in:
2021-04-13 22:11:52 +08:00
parent 89349705fd
commit 2fd996aa4c
3 changed files with 37 additions and 23 deletions

View File

@ -9,6 +9,7 @@ package json
import (
"encoding/json"
"fmt"
"reflect"
"strings"
@ -53,9 +54,14 @@ func (pjt *ParseJSONTree) Parse(pathList []string) (*DynamicJSON, error) {
// 为数组的处理
pathArr := strings.Split(path, "[]")
for idx, item := range pathArr {
val := gjson.Get(source, item)
isComplextType := val.IsArray()
if len(pathArr)-1 == idx {
// 当前是最后一项,说明不是数组
result.SetValue(item, gjson.Get(source, item).Raw)
if isComplextType {
fmt.Println("这是一个数组")
}
result.SetValue(item, val.Raw, isComplextType)
continue
}
}