dongyan7172
2019-05-06 15:31
浏览 102
已采纳

如何在GO中初始化结构的嵌套数组?

I'm having this struct:

type RemedyCircuitsResp struct {
    Circuits []struct {
        RemedyCircuitID            string `json:"RemedyCircuitId"`
        Status                     string `json:"Status"`
        VendorName                 string `json:"VendorName"`
        VendorCommunityID          int    `json:"VendorCommunityId"`
        CommunityID                int    `json:"CommunityId"`
        ZLocCommunityID            int    `json:"ZLocCommunityId"`
        CircuitType                string `json:"CircuitType"`
        InstalledSpeed             string `json:"InstalledSpeed"`
        CircuitID                  string `json:"CircuitId"`
        CircuitSpeed               string `json:"CircuitSpeed"`
        CircuitFunction            string `json:"CircuitFunction"`
        ContractID                 string `json:"ContractId"`
        ALocName                   string `json:"ALocName"`
        ZLocName                   string `json:"ZLocName"`
        ExpectedMonthlyCircuitCost string `json:"ExpectedMonthlyCircuitCost"`
        ExpectedOneTimeCircuitCost string `json:"ExpectedOneTimeCircuitCost"`
        TotalCost                  string `json:"TotalCost"`
        CustomerMakeReadyComplete  string `json:"CustomerMakeReadyComplete"`
        CarrierOriginalDueDate     string `json:"CarrierOriginalDueDate"`
        CarrierCurrentDueDate      string `json:"CarrierCurrentDueDate"`
        CarrierCompletion          string `json:"CarrierCompletion"`
        EnaTurnUpDate              string `json:"EnaTurnUpDate"`
        SiteVisit                  string `json:"SiteVisit"`
        DisconnectRequested        string `json:"DisconnectRequested"`
        DisconnectEffective        string `json:"DisconnectEffective"`
    } `json:"Circuits"`
    ResponseStatus struct {
        ErrorCode  string `json:"ErrorCode"`
        Message    string `json:"Message"`
        StackTrace string `json:"StackTrace"`
        Errors     []struct {
            ErrorCode string `json:"ErrorCode"`
            FieldName string `json:"FieldName"`
            Message   string `json:"Message"`
        } `json:"Errors"`
    } `json:"ResponseStatus"`
}

I've tried to initialize Circuits and Errors but I don't know how:

    allCircuits := RemedyCircuitsResp{}
    allCircuits.Circuits = make([]RemedyCircuitsResp.Circuits, 0)
    allCircuits.ResponseStatus.Errors = make([]RemedyCircuitsResp.ResponseStatus.Errors, 0)

Visual Studio Code says:

RemedyCircuitsResp.Circuits undefined (type RemedyCircuitsResp has no method Circuits)
RemedyCircuitsResp.ResponseStatus undefined (type RemedyCircuitsResp has no method ResponseStatus)

1条回答 默认 最新

相关推荐 更多相似问题