我有这个结构:
type ResponseStatus struct {
StatusCode int
Message string
Data string `json:"data"`
}
type Pets struct {
Id int `json:"id"`
Name string `json:"name"`
Age int `json:"age"`
Type string `json:"type"`
}
这是我的json结果:
{
"StatusCode": 200,
"Message": "Hello framework - OK",
"data": "[{\"id\":1,\"name\":\"george\",\"age\":2,\"type\":\"dog\"},{\"id\":2,\"name\":\"walter\",\"age\":1,\"type\":\"rabbit\"},{\"id\":3,\"name\":\"tom\",\"age\":1,\"type\":\"cat\"},{\"id\":4,\"name\":\"doggo\",\"age\":5,\"type\":\"dog\"},{\"id\":5,\"name\":\"torto\",\"age\":3,\"type\":\"turtle\"},{\"id\":6,\"name\":\"jerry\",\"age\":1,\"type\":\"hamster\"},{\"id\":7,\"name\":\"garf\",\"age\":2,\"type\":\"cat\"},{\"id\":8,\"name\":\"milo\",\"age\":4,\"type\":\"dog\"},{\"id\":9,\"name\":\"kimi\",\"age\":2,\"type\":\"cat\"},{\"id\":10,\"name\":\"buck\",\"age\":1,\"type\":\"rabbit\"}]"
}
如何将结果数据中的双引号转义为json,如下所示:
{
"StatusCode": 200,
"Message": "Hello framework - OK",
"data": [
{"id": 1,"name": "george","age": 2,"type": "dog"},
{"id": 2,"name": "walter","age": 1,"type": "rabbit"},
{"id": 3,"name": "tom","age": 1,"type": "cat"},
{"id": 4,"name": "doggo","age": 5,"type": "dog"},
{"id": 5,"name": "torto","age": 3,"type": "turtle"},
{"id": 6,"name": "jerry","age": 1,"type": "hamster"},
{"id": 7,"name": "garf","age": 2,"type": "cat"},
{"id": 8,"name": "milo","age": 4,"type": "dog"},
{"id": 9,"name": "kimi","age": 2,"type": "cat"},
{"id": 10,"name": "buck","age": 1,"type": "rabbit"}
]
}