Struct
转换Struct
方法用于将整个Json
包含的数据内容转换为指定的数据格式或者对象。
data := ` { "count" : 1, "array" : ["John", "Ming"] }` if j, err := gjson.DecodeToJson(data); err != nil { panic(err) } else { type Users struct { Count int Array []string } users := new(Users) if err := j.Scan(users); err != nil { panic(err) } fmt.Printf(`%+v`, users) } // Output: // &{Count:1 Array:[John Ming]} |