这种写法是什么意思

cups_book · · 1202 次点击
To unmarshal JSON into a struct, Unmarshal matches incoming object keys to the keys used by Marshal (either the struct field name or its tag), preferring an exact match but also accepting a case-insensitive match. **事实上,是不看tag的....., 只看struct field, 大小写不敏感倒是真的.** ```go package main import ( "fmt" "encoding/json" ) type User struct { NamE string "nam"//结构的字段可以带标签字面量,成为字段的属性 // Pass string "pass" // Age int16 "age" } func main() { var json_string = `{"name":"zhangsan","pass":"123456","age":20}` // usr := &User{} var usr = new (User) json.Unmarshal([]byte(json_string), usr)//解析json字符串 fmt.Println(usr) } ``` 输出: &{zhangsan} By default, object keys which don't have a corresponding struct field are ignored (see Decoder.DisallowUnknownFields for an alternative). **json对象的keys没有在struct中找到对应的keys,就会被忽略.**
#9
更多评论
go结构体标签 https://blog.csdn.net/benben_2015/article/details/79807792
#1
嗯,我遇到的是这个错误: json: cannot unmarshal array into Go struct field 意思是说...go没法反序列化一个array到go的结构体字段里去..?
#2