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

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

遍歷 golang 中的一系列 struts

遍歷 golang 中的一系列 struts

Go
繁星coding 2022-11-23 15:28:29
我的術(shù)語可能不適用,所以我使用了一些 python 術(shù)語。在 golang 中嘗試做的是迭代一個具有這樣存儲值的支柱(這是我從 api 返回的)[{STOREA 0 0 0} {STOREB 0 0 0} {STOREC 0 0 0} {STORED 0 0 0}]在 python 中,我將其稱為字典列表。當(dāng)我將鼠標(biāo)懸停在可視代碼中的值上時,它指出:field itemData []struct{代碼字符串 "json:"Code""; 項目 int "json:"項目""; 價格 float64 "json:"價格""; 數(shù)量 int "json:"數(shù)量""}package main// I think this is the right way to interpret what visual code statedtype itemData struct {    Code string  `json:"Code"`    Items int     `json:"Items"`    Price   float64 `json:"Price"`    Qty int     `json:"Qty"`    }//I'm trying to simulate the api response by storing it in a varible like this but I think the [] are an issue and im doing it incorrectlyvar storeData = itemData[{STOREA 0 0 0} {STOREB0 0 0} {STOREC 0 0 0} {STORED0 0 0}] // I think the [ ] brackets are causing an issue//The idea is I can iterate over it like this:for k,v := range storeData {    fmt.Printf(k,v)    }
查看完整描述

2 回答

?
30秒到達(dá)戰(zhàn)場

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

推薦給Go 之旅 - Slice


然后試試這個:


    var storeData = []itemData{{"STOREA", 0, 0, 0}, {"STOREB", 0, 0, 0}, {"STOREC", 0, 0, 0}, {"STORED", 0, 0, 0}}

    for k, v := range storeData {

        fmt.Println(k, v)

    }

https://go.dev/play/p/aRaJlqKe00L


查看完整回答
反對 回復(fù) 2022-11-23
?
函數(shù)式編程

TA貢獻(xiàn)1807條經(jīng)驗 獲得超9個贊

你所擁有的slice是itemData( struct)。使用切片文字用值初始化切片非常簡單。它看起來像這樣:


    storeData := []itemData{

        {

            Code:  "STOREA",

            Items: 0,

            Price: 0,

            Qty:   0,

        },

        {

            Code:  "STOREB0",

            Items: 0,

            Price: 0,

        },

        {

            Code:  "STOREC",

            Items: 0,

            Price: 0,

            Qty:   0,

        },

        {

            Code:  "STORED0",

            Items: 0,

            Price: 0,

        },

    }

    for i, v := range storeData {

        fmt.Printf("index: %d, value: %v\n", i, v)

    }


查看完整回答
反對 回復(fù) 2022-11-23
  • 2 回答
  • 0 關(guān)注
  • 125 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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