json 格式
{
"code": 200,
"message": "success",
"data": {
"diff": 1,
"list": [{
"exception_name": "(部分)联系人已离职\/群邮箱不在用",
"customer_name": "奥术大师多",
"legal_name": "sdasdss",
"up_json_email": [],
"local_json_email": [{
"name": "262",
"email": "[email protected]",
"change_status": 0
}, {
"name": "115",
"email": "[email protected]",
"change_status": 2
}, {
"name": "wg",
"email": "[email protected]",
"change_status": 0
}],
"change_color": 0
}],
"title": [{
"label": "异常原因",
"prop": "exception_name"
}, {
"label": "客户(实控人)",
"prop": "customer_name"
}, {
"label": "法律主体",
"prop": "legal_name"
}, {
"label": "收件人信息",
"prop": "local_json_email"
}],
"tips1": "系统识别到以下法律主体的收件人信息有异常,请核准:",
"tips2": "点击【确认】忽略数据差异,继续发送邮件。"
}
}
go 写法
package main
import (
"encoding/json"
"fmt"
)
type Item struct {
ExceptionName string `json:"exception_name"`
CustomerName string `json:"customer_name"`
LegalName string `json:"legal_name"`
UpJsonEmail []string `json:"up_json_email"`
LocalJsonEmail []struct {
Name string `json:"name"`
Email string `json:"email"`
ChangeStatus int `json:"change_status"`
} `json:"local_json_email"`
ChangeColor int `json:"change_color"`
}
type Title struct {
Label string `json:"label"`
Prop string `json:"prop"`
}
type Data struct {
Diff int `json:"diff"`
List []Item `json:"list"`
Title []Title `json:"title"`
Tips1 string `json:"tips1"`
Tips2 string `json:"tips2"`
}
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
Data Data `json:"data"`
}
func main() {
data := Data{
Diff: 1,
List: []Item{
{
ExceptionName: "(部分)联系人已离职/群邮箱不在用",
CustomerName: "奥术大师多",
LegalName: "sdasdss",
UpJsonEmail: []string{
},
LocalJsonEmail: []struct {
Name string `json:"name"`
Email string `json:"email"`
ChangeStatus int `json:"change_status"`
}{
{
Name: "262",
Email: "[email protected]",
ChangeStatus: 0,
},
{
Name: "115",
Email: "[email protected]",
ChangeStatus: 2,
},
{
Name: "wg",
Email: "[email protected]",
ChangeStatus: 0,
},
},
ChangeColor: 0,
},
},
Title: []Title{
{
Label: "异常原因",
Prop: "exception_name",
},
{
Label: "客户(实控人)",
Prop: "customer_name",
},
{
Label: "法律主体",
Prop: "legal_name",
},
{
Label: "收件人信息",
Prop: "local_json_email",
},
},
Tips1: "系统识别到以下法律主体的收件人信息有异常,请核准:",
Tips2: "点击【确认】忽略数据差异,继续发送邮件。",
}
response := Response{
Code: 200,
Message: "success",
Data: data,
}
b, err := json.MarshalIndent(response, "", " ")
if err != nil {
fmt.Println("error:", err)
}
fmt.Println(string(b))
}
root@debiancc:~/www/test# go run test.go
{
"code": 200,
"message": "success",
"data": {
"diff": 1,
"list": [
{
"exception_name": "(部分)联系人已离职/群邮箱不在用",
"customer_name": "奥术大师多",
"legal_name": "sdasdss",
"up_json_email": [],
"local_json_email": [
{
"name": "262",
"email": "[email protected]",
"change_status": 0
},
{
"name": "115",
"email": "[email protected]",
"change_status": 2
},
{
"name": "wg",
"email": "[email protected]",
"change_status": 0
}
],
"change_color": 0
}
],
"title": [
{
"label": "异常原因",
"prop": "exception_name"
},
{
"label": "客户(实控人)",
"prop": "customer_name"
},
{
"label": "法律主体",
"prop": "legal_name"
},
{
"label": "收件人信息",
"prop": "local_json_email"
}
],
"tips1": "系统识别到以下法律主体的收件人信息有异常,请核准:",
"tips2": "点击【确认】忽略数据差异,继续发送邮件。"
}
}
root@debiancc:~/www/test#