Compare commits
No commits in common. "186f103fa5a194d6b6fd919b4bed6a2b7a5604c5" and "1cae7173d639a46182d0ef03103fd4485ebe3d51" have entirely different histories.
186f103fa5
...
1cae7173d6
@ -8,7 +8,6 @@
|
||||
package json_tool
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
@ -17,15 +16,12 @@ import (
|
||||
// Author : go_developer@163.com<张德满>
|
||||
//
|
||||
// Date : 10:53 PM 2022/1/9
|
||||
func GetJSONDataStruct(data string) ([]string, error) {
|
||||
if !gjson.Valid(data) {
|
||||
return make([]string, 0), errors.New("JSON format is invalid")
|
||||
}
|
||||
func GetJSONDataStruct(data string) []string {
|
||||
pathList := make([]string, 0)
|
||||
r := gjson.Parse(data)
|
||||
r.ForEach(func(key, value gjson.Result) bool {
|
||||
if value.IsObject() {
|
||||
list, _ := GetJSONDataStruct(value.String())
|
||||
list := GetJSONDataStruct(value.String())
|
||||
for _, k := range list {
|
||||
pathList = append(pathList, key.String()+"."+k)
|
||||
}
|
||||
@ -37,7 +33,7 @@ func GetJSONDataStruct(data string) ([]string, error) {
|
||||
if !dataList[0].IsObject() && !dataList[0].IsArray() {
|
||||
pathList = append(pathList, key.String())
|
||||
} else {
|
||||
list, _ := GetJSONDataStruct(dataList[0].String())
|
||||
list := GetJSONDataStruct(dataList[0].String())
|
||||
for _, k := range list {
|
||||
pathList = append(pathList, key.String()+".[]."+k)
|
||||
}
|
||||
@ -53,5 +49,5 @@ func GetJSONDataStruct(data string) ([]string, error) {
|
||||
|
||||
return true
|
||||
})
|
||||
return pathList, nil
|
||||
return pathList
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user