5.3.2版本publish接口发送json指令报错,

这个是请求体
{
“payload_encoding”: “plain”,
“topic”: “123”,
“qos”: 0,
“payload”: {
“command”: “a1”
},
“properties”: {
“payload_format_indicator”: 0,
“message_expiry_interval”: 0,
“response_topic”: “some_other_topic”,
“correlation_data”: “string”,
“user_properties”: {
“foo”: “bar”
},
“content_type”: “application/json”
},
“retain”: false
}
报错内容如下:
{

“code”: “BAD_REQUEST”,

“message”: “{"value":{"command":"a1"},"reason":{"expected":"binary()"},"path":"root.payload","kind":"validation_error"}”

}
由于新设备只支持 {
“command”: “a1”
}这样的命令。此外,4.4.19版本用{
“topic”: “123”,
“payload”: {
“command”: “a1”
},
“qos”: 0,
“retain”: false,
“clientid”: “example”,
“content_type”: “application/json”
}就不报错。
如何在5.3.2版本上解决呢?

payload 这个字段只支持字符串格式,不能放一个 Object。所以你把它 json encode 一下,改成这样就可以了:

"payload": "{
\"command\": \"a1\"
}"

谢谢