dongwo2772
2018-03-25 18:37
浏览 501
已采纳

Go中的嵌套数组结构

I have started using https://mholt.github.io/json-to-go/ to turn API JSON into go structs and I really like it, however I am stuck on how to initialize the Filters array struct in the Report Definition struct shown below.

type ReportDefinition struct {
    ReportName string `json:"reportName"`
    ReportType string `json:"reportType"`
    Product    string `json:"product"`
    Email      string `json:"email"`
    CreatedBy  string `json:"createdBy"`
    Duration   struct {
        Duration  string      `json:"duration"`
        StartDate interface{} `json:"startDate"`
        EndDate   interface{} `json:"endDate"`
    } `json:"duration"`
    Filters []struct {
        Column struct {
            ColumnName string `json:"columnName"`
            Value      string `json:"value"`
        } `json:"column"`
        Operator string `json:"operator"`
    } `json:"filters"`
    SortBy            interface{}   `json:"sortBy"`
    ReportGroup       interface{}   `json:"reportGroup"`
    ReportOnHierarchy bool          `json:"reportOnHierarchy"`
    IsReportPreview   string        `json:"isReportPreview"`
    OutputRecordCount interface{}   `json:"outputRecordCount"`
    Schedule          interface{}   `json:"schedule"`
    Columns           []interface{} `json:"columns"`
}

I cannot seem to reference the items declared within the Filters struct or even the Filters struct in order to create a new Filter item and append it to Filters.

Is it possible to reference the Column struct with the ReportDefinition written as is? Or am I am doing something silly and I should just declare Filters outside of the ReportDefinition structure?

图片转代码服务由CSDN问答提供 功能建议

我已经开始使用 https://mholt.github.io/json-to-go/ 将API JSON转换为go结构,我真的很喜欢它,但是我坚持如何初始化 </ p>

  type ReportDefinition结构{
 ReportName字符串`json:“ reportName”`
 ReportType字符串`json:“ reportType  “`
产品字符串`json:” product“`
电子邮件字符串`json:” email“`
 CreatedBy字符串`json:” createdBy“`
持续时间结构{
持续时间字符串`json:” duration“  `
 StartDate接口{}`json:“ startDate”`
 EndDate接口{}`json:“ endDate”`
}`json:“ duration”`
过滤器[] struct {
列struct {\  n ColumnName字符串`json:“ columnName”`
值字符串`json:“ value”`
}`json:“ column”`
运算符字符串`j 儿子:“操作员”  reportOnHierarchy“ 
 IsReportPreview字符串`json:” isReportPreview“`
 OutputRecordCount接口{}`json:” outputRecordCount“`
 Schedule接口{}`json:” schedule“`
列[] interface {}`json  :“ columns”`
} 
 </ code> </ pre> 
 
 

我似乎无法引用在Filters结构甚至是Filters结构中声明的项目来创建新的Filter项目 并将其附加到过滤器中。</ p>

是否可以引用具有ReportDefinition的Column结构? 还是我在做一些愚蠢的事情,我应该在ReportDefinition结构之外声明Filters?</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题