gpt4 book ai didi

json - 嵌套映射返回 json array[]

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

如何创建嵌套的 JSON 数组?还有其他简单的方法吗?

我试过这个:

var m1 = make(map[string]interface{})
m1 = append(tickets, ptotal) //error is here
i.Data["json"] = m1
i.ServeJSON()

但它显示此错误:

cannot use append(tickets, ptotal) (type []interface {}) as type map[string]interface {} in assignment

我可以这样做,但它根本没有嵌套:

// some := append(tickets, map[string]int64{"totalpage": ptotal})

我想要这个 JSON:

[
{tickets
name:value,
},
],
[
{
totalpage: 10
}
]

我想要Playground of mine

最佳答案

var tickets []interface{}
var ptotal int64
tickets, ptotal, err := models.GetAllTicket(query, fields, sortby, order, offset, limit)
if err != nil {
// bulabula
}
i.Data["json"] = append(tickets, map[string]int64{"totalpage": ptotal})

关于json - 嵌套映射返回 json array[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55252980/

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