나는 json이 구조체를 인코딩하는 내 서버에서 매우 간단한 http 공감을 가지고 있습니다. 하지만 그것의 공백을 보내 그냥 {}
JSON 인코딩 빈 반환 골란
나는 그것을 잘못하고 있지만 나는 아무런 오류가 있는지 모르겠다. 이건 내 JSON 인코딩입니다 : 데이터를 종료하려면 잡에
// 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 (struct)의 가능한 복제본은 "{}"(https://stackoverflow.com/questions/26327391/go-json-marshalstruct-returns) – tgogos