Go Unmarshal 리스트 컬럼 받기

1 개요[ | ]

Go Unmarshal 리스트 컬럼 받기
Go Unmarshal 리스트인 컬럼 받기
package main

import (
	"encoding/json"
	"fmt"
)

type Item struct {
	ID     int      `json:"id"`
	Name   string   `json:"name"`
	Colors []string `json:"colors"`
}

func main() {
	j1 := `{"id":1,"name":"car","colors":["red","blue"]}`
	j2 := `{"id":2,"name":"phone","colors":["black","gray","white"]}`

	item1 := Item{}
	if err := json.Unmarshal([]byte(j1), &item1); err != nil {
		panic(err)
	}
	fmt.Printf("item1: %+v\n", item1)

	item2 := Item{}
	if err := json.Unmarshal([]byte(j2), &item2); err != nil {
		panic(err)
	}
	fmt.Printf("item2: %+v\n", item2)
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}