私はjsonが構造体をエンコードする私のサーバーで非常に単純なhttpの共鳴を持っています。しかし、それはちょうど空白を送信する{}
JSONエンコード空白を返すGolang
私はそれが間違っているかどうかは分かりませんが、私はエラーが表示されません。これは私のJSONエンコードです:データを終わらrecievingで
// Set uuid as string to user struct
user := User{uuid: uuid.String()}
fmt.Println(user) // check it has the uuid
responseWriter.Header().Set("Content-Type", "application/json")
responseWriter.WriteHeader(http.StatusCreated)
json.NewEncoder(responseWriter).Encode(user)
あります
Content-Type application/json
Content-Length 3
STATUS HTTP/1.1 201 Created
{}
は、なぜそれが私のUUIDデータを与えるものではありませんか?エンコーディングに何か問題がありますか?
エクスポートするフィールド名
はこれを試してみてください。重複している可能性のあるhttps://stackoverflow.com/questions/26327391/go-json-marshalstruct-returnsを参照してください。 –
それがうまくいくか試してみてください。 – Sir
[json.Marshal(構造体)が "{}"を返す可能性があります(https://stackoverflow.com/questions/26327391/go-json-marshalstruct-returns) – tgogos