string类型进行json转换成struct类型

问题解释

"{\"name\":\"xxx\",\"age\":12}"
type Person struct {
	Name string `json:"name"`
	Age int `json:"age"`
}
var p Person
pStr := "{\"name\":\"xxx\",\"age\":12}"
err := json.Unmarshal([]byte(pStr), &p)
`"{\"name\":\"xxx\",\"age\":12}"`json: cannot unmarshal string into Go value of type XXX

解决方式

json.Unmarshalstrconv.Unquote(pStr)