杜松子酒拦截请求正文

I am using go-gin as server and trying to decode the request body. When I send request which has both the strings

{
    "name": "abc"
}

The following code decodes it correctly:

var decodedBody map[string]string
err = json.NewDecoder(c.Request.Body).Decode(&decodedBody)

But if I send

{
    "id": 1
}

The following code gives me a blank map

var decodedBody map[string]int
err = json.NewDecoder(c.Request.Body).Decode(&decodedBody)

Not sure what am I missing here. Any pointers?

because you set the decodeBody's data type with string,if your value is not the string value, it will not decode the correct value,{"id":1},it's value's type is int,not the string.