Golang杜松子酒BindJSON省略单引号

时间:2020-04-15 11:51:25

标签: json go post go-gin

在GIN POST方法中,BindJSON在请求正文字段中省略了单引号
这是我的POST方法

string            country
i live in NY      usa
chicago is best   usa
delhi is xyz      india

这是我的CURL请求

func TestPost(c *gin.Context) {
    var tmp struct{ Tmp string }
    c.BindJSON(&tmp)
    log.Printf("%+v\n", tmp)
    /* my work */
    c.Status(200)
}

在GIN日志中

2020/04/15 11:35:39 {Tmp:示例字符串GIN具有单引号}

[GIN] 2020/04/15-11:35:39 | 200 | 209.71µs | 127.0.0.1 |开机自检“ /”

如您在日志中所见,GIN周围没有单引号 我的用例是保留作为有效负载传递的单引号

请帮助!!!

1 个答案:

答案 0 :(得分:0)

问题出在CURL

curl -X POST localhost:5005 --data '{"tmp":"example string '\''GIN'\'' have single quote"}'
相关问题