数组支持递归解析
This commit is contained in:
@ -75,6 +75,7 @@ func (oj *ownJson) Marshal(marshalType string) ([]byte, error) {
|
||||
// generateStructField 递归解析
|
||||
func (oj *ownJson) generateStructField(rootPath string, currentName string, currentResult gjson.Result) {
|
||||
structPath := oj.getPath(rootPath, currentName)
|
||||
fmt.Println(structPath)
|
||||
if currentResult.IsBool() {
|
||||
// bool类型
|
||||
oj.structBuilder.AddField(structPath, "", true, "", false)
|
||||
@ -123,8 +124,8 @@ func (oj *ownJson) generateStructField(rootPath string, currentName string, curr
|
||||
return
|
||||
}
|
||||
if arrList[0].IsArray() {
|
||||
// 数组就不递归处理了, 支持到二维
|
||||
oj.structBuilder.AddField(structPath, "", [][]any{}, "", false)
|
||||
// 数组递归处理
|
||||
oj.generateStructField(structPath+".[]", "", arrList[0])
|
||||
return
|
||||
}
|
||||
// 对象结构,递归处理
|
||||
@ -141,5 +142,8 @@ func (oj *ownJson) getPath(root string, currentName string) string {
|
||||
if root == "" {
|
||||
return currentName
|
||||
}
|
||||
if currentName == "" {
|
||||
return root
|
||||
}
|
||||
return root + "." + currentName
|
||||
}
|
||||
|
Reference in New Issue
Block a user