package main
import (
"encoding/json"
"fmt"
)
type Screen struct {
Size float32
Resx,Resy int
}
type Battery struct {
Capacity int
}
func gen_json_data() []byte {
raw:=&struct {
Screen
Battery
Hasidool bool
}{
Screen:Screen{
Size: 5.5,
Resx: 1920,
Resy: 1080,
},
Battery:Battery{
2910,
},
Hasidool:true,
}
jsondata,_:=json.Marshal(raw)
fmt.Println(jsondata)
return jsondata
}
func main() {
jsondata:=gen_json_data()
fmt.Println(string(jsondata))
screemandtouch:= struct {
Screen
hasid bool
}{}
json.Unmarshal(jsondata,&screemandtouch)
fmt.Printf("%+v \n",screemandtouch)
}
08-30
338
04-22
1万+
10-29
457
12-15
264