Files
go-easy-utils/jsonUtil/json_to_struct_example_test.go
jeffery e9cc195c39 Feature/example test (#24)
example docs
2023-04-12 15:09:44 +08:00

27 lines
418 B
Go

package jsonUtil
import "fmt"
func ExampleJsonToStruct() {
jsonData := `{
"name": "make",
"age": "22",
"is_use": "1"
}`
var people struct {
Name string `json:"name,omitempty"`
Age int `json:"age"`
IsUse bool `json:"is_use"`
}
if err := JsonToStruct(jsonData, &people); err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v", people)
// Output:
// {Name:make Age:22 IsUse:true}
}