golang之Json編碼解碼
編碼
json.Marshal()
func Marshal(v interface{}) ([]byte, error)
解碼
json.Unmarshal()
func Unmarshal(data []byte, v interface{}) error
json TO struct線上轉譯 :http://json2struct.mervine.net/
json to go滴滴團隊研發(據說比官方快6倍):https://github.com/json-iterator/go
Warning:Json轉結構體,或結構體轉Json,結構體首字母必須大寫!!!
package main import ( "fmt" "encoding/json" ) func main() { type Student struct { Name string Age int Classes []string Prices float64 } st := &Student { "xiaoming", 18, []string{"math","english","chinese"}, 9.99, } result, err := json.Marshal(st) if(err == nil) { fmt.Println(string(result)) } } //{"Name":"xiaoming","Age":18,"Classes":["math","english","chinese"],"Prices":9.99}