gpt4 book ai didi

dictionary - 使用 Golang 将映射数据输入到结构中

转载 作者:数据小太阳 更新时间:2023-10-29 03:22:21 25 4
gpt4 key购买 nike

<分区>

我想使用 Golang 将我的 map 数据放入另一个 map 数据。但是它有结构类型。

这是我的代码。

birth := make(map[string]interface{})

birth["docType"] = "registerBirth"
birth["agencyCd"] = string(args[0])
birth["birthYmd"] = string(args[1])
birth["lsTypeNm"] = string(args[2])
birth["monthDiff"] = string(args[3])
birth["nationNm"] = string(args[4])
birth["sexNm"] = string(args[5])
birth["regType"] = string(args[9])
birth["regYmd"] = string(args[10])

我想把这个 map 数据放到另一个 map 上,但是我想使用struct类型。

cattle := make(map[string]interface{})

cattle["docType"] = "information"
cattle["birthInfo"] = struct {
birth map[string]interface{}
}{
birth,
}

但是,当我得到数据时..结果是这样的。

{"birthInfo":{},"docType":"information"}

这是我想要的例子。

"birthInfo": {
"birthYmd": "2018-07-25",
"cattleNo": "cow001",
"docType": "registerBirth",
"farmNo": "farm001",
"flatEartagNo": "eartag123123",
"lsTypeNm": "황소",
"monthDiff": "2018-07",
"nationNm": "austria",
"regType": "직접",
"regYmd": "20185-07-25",
"sexNm": "M"
},
"docType": "information",
...

提前致谢。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com