// convert struct to json
package main
import (
"fmt"
"encoding/json"
)
type Host struct {
IP string
Name string
}
func main() {
m := Host{Name: "Sky",IP: "192.168.23.92"}
b,err := json.Marshal(m)
if err != nil {
fmt.Println("Umarshal Failed:",err)
return
}
fmt.Println("json:",string(b))
}
output:
json: {“IP”:”192.168.23.92”,”Name”:”Sky”}
@H_301_43@ 原文链接:https://www.f2er.com/go/187520.html