Online JSON to Golang Struct

我要 Format JSON JSON to Postman
type JSONData struct {
	Name string `json:"name"`
	Code int `json:"code"`
	List []struct {
		Day int `json:"day"`
	} `json:"list"`
}
使用结构体
package main

import (
    "encoding/json"
    "fmt"
)

type JSONData struct {
    Name string `json:"name"`
    Code int    `json:"code"`
    List []List `json:"list"`
}
type List struct {
    Day int `json:"day"`
}

func main() {
    var jsonData JSONData
    jsonData.List = append(jsonData.List, List{1})
    jsonData.List = append(jsonData.List, List{2})

    respJson := JSONData{
        Code: 1,
        Name: Xiao Fang,
        List: jsonData.List,
    }
    b, err := json.Marshal(respJson)
    if err != nil {
        fmt.Println("JSON ERR:", err)
    }
    fmt.Println(string(b))
}
                    

Online JSON to Golang Struct Tool: To convert Golang to JSON, you need to define a struct first. If there are too many JSON fields, our workload will increase significantly. Bejson's online JSON to Golang Struct tool can quickly generate the required struct for us.

You recently used:

收藏: favorite Menu QQ