http服务端在把json串写入http.ResponseWriter对象的时候我们常用的方式如下:

//方法一:
func ...(w http.ResponseWriter, r *http.Request) {
	s,_:=json.Marshal(userinfo)
	fmt.Fprint(w,string(s))
}
//方法二:
func ...(w http.ResponseWriter, r *http.Request) {
	s,_:=json.Marshal(userinfo)
	w.Write(s)
}

里面出现了一个问题,方法一再使用的时候如果存在%号,responsebody出现了

golang采坑记 一(http与json)

方法二则正常

因此推敲出若果存在内置的方法,请务必使用内置的方法,以免引起未知的问题

 

相关文章:

  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2022-02-08
  • 2021-05-09
  • 2021-10-23
  • 2021-09-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2021-04-10
  • 2021-12-29
相关资源
相似解决方案