【发布时间】:2019-04-02 18:25:01
【问题描述】:
我想使用块布局格式向我的 slack 应用程序发送消息。我在 PHP 中创建了一个关联数组,然后使用 json_encode() 将其转换为 JSON。问题是它没有转换为 slack 所期望的 JSON 格式,并且我收到错误“无效的块格式”。这是我的代码,输出和 slack 期望的输出。
$data = array(
'blocks' => array(
'type' => 'mrkdwn',
'text' => 'Danny Torrence left the following review for your property'
),
);
$data = json_encode($data);
我得到以下输出:
{"blocks":{"type":"mrkdwn","text":"Danny Torrence left the following review for your property"}}
但是,Slack 期望 JSON 格式如下:
{"blocks":["type":"mrkdwn","text":"Danny Torrence left the following review for your property"]}
最后我只需要将一个'{' 转换为'[' 和一个'}' 转换为']'。我将不胜感激。
谢谢
【问题讨论】: