引入复杂数据类型 & 支持是slice/map
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user