type ServerTime struct {
Iso string `json:"iso"`
Epoch string `json:"epoch"`
}
Iso是一个string类型的,ServerTime这个结构体的成员,后面的`json:"iso"` 是什么意思?
谢谢🙏
Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an InvalidUnmarshalError.
```go
package main
import (
"fmt"
"encoding/json"
)
type User struct {
Name string "name"//结构的字段可以带标签字面量,成为字段的属性
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)
}
```
#5
更多评论
嗯,我遇到的是这个错误:
json: cannot unmarshal array into Go struct field
意思是说...go没法反序列化一个array到go的结构体字段里去..?
#2