Go Lang RESTful API 不工作 JSON

我正在尝试在 Go Lang 上创建一个 RESTful API,返回 JSON 值。当我加载页面时,我没有在页面上获得任何价值。有人可以帮我在这里..?


type sessiond struct{

   apiKey string `json:"apiKey"`

   token string `json:"token"`

}


func dummy(w http.ResponseWriter, r *http.Request) {

   se:=sessiond{apiKey:key,token:"erer"}

   log.Println(se);    // Iam getting the value here ! but nothing on the page.

   w.Header().Set("Content-Type", "application/json; charset=UTF-8")

   w.WriteHeader(http.StatusOK)

      if err := json.NewEncoder(w).Encode(se); err != nil {

      panic(err)

   }

   //res.R200(w, se)

}


慕后森
浏览 158回答 1
1回答

天涯尽头无女友

sessiond通过以大写字母开头的字段名称导出类型中的字段。type sessiond struct{   ApiKey string `json:"apiKey"`   Token string `json:"token"`}JSON 编码器和解码器会忽略未导出的字段。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go