gpt4 book ai didi

json - 在 JSON 对象中发送数组时出错

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

为了用 Iris Go 发送这个 JSON

{
"response_type": "in_channel",
"text": "It's 80 degrees right now.",
"attachments": [
{
"text":"Partly cloudy today and tomorrow"
}
]
}

我正在尝试这个但是没有用

ctx.JSON(iris.Map{
"text": "It's 80 degrees right now.",
"response_type": "in_channel",
"attachments":[{ "text": "Partly cloudy today and tomorrow" }],
})

因为附件行出现如下错误

syntax error: unexpected {, expecting expression

你知道怎么解决吗?

最佳答案

在您的 Go 代码中,您没有为数组或其元素指定类型。假设您希望它是 iris.Map:

ctx.JSON(iris.Map{
"text": "It's 80 degrees right now.",
"response_type": "in_channel",
"attachments": []iris.Map{iris.Map{ "text": "Partly cloudy today and tomorrow" }},
})

关于json - 在 JSON 对象中发送数组时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48386687/

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