第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

具有多個(gè)數(shù)據(jù)的 GoLang JSON 負(fù)載準(zhǔn)備

具有多個(gè)數(shù)據(jù)的 GoLang JSON 負(fù)載準(zhǔn)備

Go
慕勒3428872 2023-06-19 15:15:58
我想以下面給出的格式創(chuàng)建 JSON 負(fù)載。我想要一個(gè)準(zhǔn)備給定格式的代碼或模式。{    transactiontype: 'DDDDD'    emailType: 'QQQQQQ'    template: {        templateUrl: 'xry.kk'        templateName: 'chanda'    }    date: [        {            UserId: 1            Name: chadnan        },        {            UserId: 2            Name: kkkkkk        }    ]}
查看完整描述

3 回答

?
慕容3067478

TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊

希望這可以幫助 :


type Template struct {

TemplateURL string `json:"templateUrl" param:"templateUrl"`

TemplateName string `json:"templateName" param:"templateName"`

}


type Date struct {

UserId string `json:"UserId" param:"UserId"`

Name string `json:"Name" param:"Name"`

}

type NameAny struct {

*Template

TransactionType string `json:"transactiontype" param:"transactiontype"`

EmailType string `json:"emailType" param:"emailType"`

Data []Date `json:"date" param:"date"`

}

Data, _ := json.Marshal(NameAny)

Json(c, string(Data))(w, r)


查看完整回答
反對 回復(fù) 2023-06-19
?
拉風(fēng)的咖菲貓

TA貢獻(xiàn)1995條經(jīng)驗(yàn) 獲得超2個(gè)贊

鑒于您的 JSON,Go 結(jié)構(gòu)是:


type AutoGenerated struct {

? ? Transactiontype string `json:"transactiontype"`

? ? EmailType? ? ? ?string `json:"emailType"`

? ? Template? ? ? ? struct {

? ? ? ? TemplateURL? string `json:"templateUrl"`

? ? ? ? TemplateName string `json:"templateName"`

? ? } `json:"template"`

? ? Date []struct {

? ? ? ? UserID int? ? `json:"UserId"`

? ? ? ? Name? ?string `json:"Name"`

? ? } `json:"date"`

}

轉(zhuǎn)換后,使用json.Marshal?(Go Struct to JSON) 和json.Unmarshal?(JSON to Go Struct)

使用您的數(shù)據(jù)完成示例:https ://play.golang.org/p/RJuGK4cY1u-


查看完整回答
反對 回復(fù) 2023-06-19
?
慕俠2389804

TA貢獻(xiàn)1719條經(jīng)驗(yàn) 獲得超6個(gè)贊

// Transaction is a struct which stores the transaction details

type Transaction struct {

    TransactionType string   `json:"transaction_type"`

    EmailType       string   `json:"email_type"`

    Template        Template `json:"template"`

    Date            []Date   `json:"date"`

}


//Template is a struct which stores the template details

type Template struct {

    TemplateURL  string `json:"template_url"`

    TemplateName string `json:"template_name"`

}


// Date is a struct which stores the user details

type Date struct {

    UserID int    `json:"user_id"`

    Name   string `json:"name"`

}

上面給定的結(jié)構(gòu)是用于存儲(chǔ) json 主體的正確數(shù)據(jù)結(jié)構(gòu),您可以使用 json 解碼器將數(shù)據(jù)完美地存儲(chǔ)到結(jié)構(gòu)中


func exampleHandler(w http.ResponseWriter, r *http.Request) {

    var trans Transaction

    decoder := json.NewDecoder(r.Body)

    err := decoder.Decode(&trans)

    if err != nil {

        log.Println(err)

    }

}



查看完整回答
反對 回復(fù) 2023-06-19
  • 3 回答
  • 0 關(guān)注
  • 145 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號