// convert json to struct
package main
import (
@H_301_7@"fmt"
@H_301_7@"encoding/json"
)
type Host struct {
IP string
Name string
}
func main() {
b := []byte(@H_301_7@`{"IP": "192.168.11.22","name": "SKY"}`)
m := Host{}
err := json.Unmarshal(b,&m)
if err != nil {
fmt.Println(@H_301_7@"Umarshal Failed:",err)
return
}
fmt.Println(@H_301_7@"m:",m)
fmt.Println(@H_301_7@"m.IP:",m.IP)
fmt.Println(@H_301_7@"m.Name:",m.Name)
}
output:
原文链接:https://www.f2er.com/go/187522.htmlm: {192.168.11.22 SKY} m.IP: 192.168.11.22 m.Name: SKY