Go json.Marshal()

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:48 판 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

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 참고[ | ]

편집자 J Jmnote Jmnote bot