如何在golang中序列化为json嵌入结构

如何在golang中序列化为json嵌入结构,json,go,Json,Go,我刚开始学围棋,但我看不清当前的任务。我需要序列化由嵌套结构组成的结构 package main import ( "encoding/json" "fmt" ) type Metadata struct { model string } type Texture struct { url string hash string metadata *Metadata } type Response struct {

我刚开始学围棋,但我看不清当前的任务。我需要序列化由嵌套结构组成的结构

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"
        }
    }
}

我在沙箱中创建了这个示例。

您需要导出字段(将名称大写):

更新的游乐场示例:


300秒重复。
type Metadata struct {
    Model string
}

type Texture struct {
    Url      string
    Hash     string
    Metadata *Metadata
}