mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-10-06 07:26:53 +08:00
26
jsonUtil/json_to_struct_example_test.go
Normal file
26
jsonUtil/json_to_struct_example_test.go
Normal file
@@ -0,0 +1,26 @@
|
||||
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}
|
||||
}
|
Reference in New Issue
Block a user