我正在尝试创建将输出 JSON 的代码。JSON 字符串表示发票及其行项目。有两个主要部分,即标题记录和项目列表。项目列表给我带来了麻烦。它包含一组发票行项目。我无法弄清楚如何构建它。有人可以帮我解决这个问题吗?
package controllers
import (
"github.com/revel/revel"
)
type Test struct {
*revel.Controller
}
type headerRecord struct {
ClientNumber string
BusinessUnit string
ValidationKey string
DataYear string
DataMonth string
TotalRevenue string
}
type dataRecord struct {
LineNumber string
InvoiceNumber string
CustomerNumber string
Zipcode string
TransDate string
Revenue string
TaxSitusRule string
TransTypeCode string
SalesTypeCode string
RegulatoryCode string
TaxExemptionCodeList []string
Geocode string
}
type request struct {
headerRecord
ItemList []dataRecord
}
func (c Test) Test() revel.Result {
request := request{
headerRecord: headerRecord{
ClientNumber: "0000000001",
BusinessUnit: "Biz Unit",
ValidationKey: "123456",
DataYear: "2016",
DataMonth: "05",
TotalRevenue: "600.00",
},
ItemList: []dataRecord{
},
}
/*
1st data record
LineNumber: "1",
InvoiceNumber: "123456",
Zipcode: "75024",
TransDate: "2016-05-15",
Revenue: "100.00",
TaxSitusRule: "05",
TransTypeCode: "050201",
SalesTypeCode: "B",
RegulatoryCode: "99",
TaxExemptionCodeList: []string{"00"},
Geocode: "",
*/
return c.RenderJSON(request)
}
手掌心
相关分类