golang http.ResponseWriter valid json

 
golang httpserver如果采用 fmt.Fprintf(w, result)来输出json数据时,若json数据包含%号,则会出现问题。
 
输出结果里面会包含(MISSING)字样,造成json格式错误。

把输出函数替换为w.Write即可。


func Action(w http.ResponseWriter, r *http.Request) { var result string //....................... // fmt.Fprintf(w, result) w.Write([]byte(result)) }
原文地址:https://www.cnblogs.com/zhangqingping/p/4308124.html