1 개요[ | ]
- Go json.Marshal()
Go
Copy
package main
import (
"encoding/json"
"fmt"
)
func main() {
bolB, _ := json.Marshal(true)
fmt.Println(string(bolB)) // true
intB, _ := json.Marshal(1)
fmt.Println(string(intB)) // 1
fltB, _ := json.Marshal(2.34)
fmt.Println(string(fltB)) // 2.34
strB, _ := json.Marshal("gopher")
fmt.Println(string(strB)) // "gopher"
slcD := []string{"apple", "peach", "pear"}
slcB, _ := json.Marshal(slcD)
fmt.Println(string(slcB)) // ["apple","peach","pear"]
mapD := map[string]int{"apple": 5, "lettuce": 7}
mapB, _ := json.Marshal(mapD)
fmt.Println(string(mapB)) // {"apple":5,"lettuce":7}
}
Loading
2 참고[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.