【发布时间】:2019-07-25 11:35:33
【问题描述】:
假设 JSON 最初看起来像:
jsonData := {
"type": "text",
"contents": []
}
我想使用循环在运行时将下面的 json 附加到 jsonData 的 contents 字段:
{
"type": "bubble",
"hero": {
"size": "full"
},
"body": {
"spacing": "sm",
"contents": [
{
"size": "xl"
},
{
"type": "box",
"contents": [
{
"flex": 0
},
{
"flex": 0
}
]
}
]
},
"footer": {
"spacing": "sm",
"contents": [
{
"type": "button",
"action": {
"type": "uri"
}
},
{
"type": "button",
"action": {
"type": "uri"
}
}
]
}
},
最终输出如下:
jsonData := {
"type": "text",
"contents": [{......},{.......}]
}
【问题讨论】:
-
在 Golang 中查找地图和切片,然后查找
json.Unmarshal -
@Seaskyways 你能用代码简要解释一下吗?因为我是 Golang 新手
-
大多数基本问题都在Tour of Go 中得到解答,只需几分钟即可完成。