golang结构体与json格式串实例代码

å·ä½ä»£ç å¦ä¸æ示ï¼

package main
import (
 "encoding/json"
 "fmt"
)
type IT struct { //ä¸å®è¦æ³¨æè¿éçæååéçåå­é¦å­æ¯å¿é¡»æ¯å¤§å
 Company string
 Subjects []string
 Isok bool
 Price float64
}
func main() {
 s := IT{"zyg", []string{"go", "python", "java"}, true, 3.14}
 buf, err := json.Marshal(s)
 if err != nil {
 fmt.Println("err = ", err)
 return
 }
 fmt.Println("buf = ", string(buf))
 buf, err = json.MarshalIndent(s, "", " ") // å°jsonå½¢å¼çå­ç¬¦ä¸²è¿è¡æ ¼å¼å
 fmt.Println(string(buf))
}

golang结构体与json格式串实例代码

Isok bool json:",string" å°Isok è¿è¡äºæ¬¡ç¼ç å¾å°å¸å°çå­ç¬¦ä¸²string

æ»ç»

以ä¸æè¿°æ¯å°ç¼ç»å¤§å®¶ä»ç»çgolangç»æä½ä¸jsonæ ¼å¼ä¸²å®ä¾ä»£ç ï¼å¸æ对大家ææ帮å©ï¼å¦æ大家æä»»ä½çé®æ¬¢è¿ç»æçè¨ï¼å°ç¼ä¼åæ¶åå¤å¤§å®¶çï¼

相关推荐