1
방금 배우기 시작했는데 현재 작업을 수행 할 수 없습니다. 중첩 구조로 구성된 구조를 직렬화해야합니다.골란에 json embed 구조체를 직렬화하는 방법
package main
import (
"encoding/json"
"fmt"
)
type Metadata struct {
model string
}
type Texture struct {
url string
hash string
metadata *Metadata
}
type Response struct {
SKIN *Texture
}
func main() {
response := Response{}
textures := &Texture{
url: "http://ely.by",
hash: "123123123123123123",
}
metadata := &Metadata{
model: "slim",
}
textures.metadata = metadata
response.SKIN = textures
result, _ := json.Marshal(response)
fmt.Println(string(result))
}
항상 { "스킨": {}} 만 출력합니다. 예상 값 :
{
"SKIN": {
"url": "http://ely.by",
"hash": "123123123123123123",
"metadata": {
"model": "slim"
}
}
}
이 예제를 샌드 박스 https://play.golang.org/p/IHktK6E33N에 만들었습니다.
합니다. – Volker