【发布时间】:2022-01-19 05:53:22
【问题描述】:
这是我在 python 文件中的 json 结构。这里的 stationList_of_state 是一个 python 列表,它有 5-10 个值,这些值会根据代码动态变化。
message = {
"type": "template",
"payload": {
"template_type": "generic",
"elements":
[
{
"buttons": [
{
"title": stationList_of_state[1],
"payload": stationList_of_state[1],
"type": "postback"
}
]
}
]
}
}
我尝试过类似这样的方法,但显示错误:
message = {
"type": "template",
"payload": {
"template_type": "generic",
"elements":
[
for i in range(len(stationList_of_state)):
{
"buttons": [
{
"title": stationList_of_state[i],
"payload": stationList_of_state[i],
"type": "postback"
}
]
}
]
}
}
有人可以建议我所做的替代方法吗?
【问题讨论】: