go萌新,转go语言的时候学到json库,出现了以下问题;结构体属性有个是指针的时候,反序列化的时候是个地址,怎么变成值
```go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
)
type OrderItem struct {
Id string `json:"id"`
Name string `json:"name"`
Price string `json:"price"`
}
type Order struct {
ID string `json:"id"`
Name *[]OrderItem `json:"name,omitempty"`
Quantity int `json:"quantity"`
TotalPrice float64 `json:"total_price"`
}
// 序列化
func dump(){
o := Order{
ID: "1234",
Name: &[]OrderItem{
{
Id: "11",
Name: "西瓜",
Price: "5.7",
},
{
Id: "22",
Name: "哈密股",
Price: "6.6",
},
},
Quantity: 50,
TotalPrice: 100,
}
//fmt.Printf("%+v\n",o)
marshal, err := json.Marshal(o) // json.Marshal 转化为json格式字符串,仅支持序列化公共的字段(小写不行)
if err != nil {
return
}
fmt.Println(string(marshal))
}
// 反序列化
func load(filepath string) {
res, err := ioutil.ReadFile(filepath)
if err != nil {
return
}
var o Order
error1 := json.Unmarshal(res, &o)
if error1 != nil {
return
}
fmt.Printf("%+v\n",o)
}
func main() {
//dump()
load("json/data.json")
}
```
data.json文件如下
```
{
"id": "1234",
"name": [
{
"id": "11",
"name": "西瓜",
"price": "5.7"
},
{
"id": "22",
"name": "哈密股",
"price": "6.6"
}
],
"quantity": 50,
"total_price": 100
}
```
打印出来长这样,怎么把name属性跟着一起打出来
{ID:1234 Name:0xc0000a4108 Quantity:50 TotalPrice:100}