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

时间:2018-01-22 17:00:26

标签: json go iris-go

为了使用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

你知道怎么解决吗?

1 个答案:

答案 0 :(得分:1)

在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" }},
})