遍历值为结构体类型的Map并append到切片类型的结构体中


package main

import "fmt"

type NotknownType struct {
	S1 string
	S2 string
	S3 string
}




func main() {
	a1 :=NotknownType{S3: "nnn",S2: "bbb",S1: "ccc"}
	a2 :=NotknownType{S3: "nnn",S2: "bbb",S1: "ccc"}
	a3 :=NotknownType{S3: "nnn",S2: "bbb",S1: "ccc"}
	mapN :=make(map[string]NotknownType)
	mapN["c1"] =a1
	mapN["c2"] =a2
	mapN["c3"] =a3
	//fmt.Print("mapN\n",mapN)
	var dd []NotknownType

	for _,item :=range mapN{
		ee:= NotknownType{}
		ee.S1=item.S1
		ee.S2=item.S2
		ee.S3=item.S3
		dd =append(dd,ee)
	}
	fmt.Println("ddddddd",dd)
	for k,v :=range dd{
		fmt.Println("kkkkkk",k)
		fmt.Println("vvvvvv",v)
	}
	

}

未完待续~

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页