feat: str转struct
This commit is contained in:
@ -28,3 +28,23 @@ func TestToMap(t *testing.T) {
|
||||
So(res.Value["age"], ShouldEqual, json.Number("18"))
|
||||
})
|
||||
}
|
||||
|
||||
func TestToStruct(t *testing.T) {
|
||||
Convey("struct转换成", t, func() {
|
||||
testData := `{
|
||||
"name": "baicha",
|
||||
"age": 18
|
||||
}`
|
||||
|
||||
type User struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
}
|
||||
var u User
|
||||
res := ToStruct(testData, &u)
|
||||
So(res.Err, ShouldBeNil)
|
||||
So(res.Value, ShouldNotBeNil)
|
||||
So(res.Value.Name, ShouldEqual, "baicha")
|
||||
So(res.Value.Age, ShouldEqual, 18)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user