`无效的直接方法参数:[object Object]`当使用`az iot hub invoke-device-method`时 [英] `Invalid direct method parameter: [object Object]` when using `az iot hub invoke-device-method`
问题描述
我使用node.js教程成功设置了一个sim设备和后端控制器:https://docs.microsoft.com/en-us/azure/iot-hub/quickstart-control-device -node
但是,如果我尝试使用带有`--method-payload`标志的`az iot hub invoke-device-method`,我会收到如下错误。
$ az iot hub invoke-device-method --hub-name< my-hub> --device-id< my-dev> --method-name SetTelemetryInterval --method-payload params.json
{
" payload":" Invalid direct method parameter:[object Object]",
" status" :400
}
with params.json:
{
" payload":2
和来自$ node SimulatedDevice.js的错误:
收到的直接方法有效负载:
[object Object]
有效负载中收到的无效区间响应
成功发送方法'SetTelemetryInterval'的响应。
只是一个决赛请注意,我在设备中创建了一个不需要有效负载的新方法,并且已收到并回复确定。
您好,
你是如何发送有效载荷的?我相信你应该序列化并将其作为字符串发送。以下是c#中将类序列化为JSON的代码, https://www.newtonsoft.com/json/ help / html / SerializingJSON.htm
I've successfully set up a sim device and backend controller using the node.js tutorial: https://docs.microsoft.com/en-us/azure/iot-hub/quickstart-control-device-node
However, if I try to use `az iot hub invoke-device-method`with the `--method-payload` flag, I am getting errors as below.
$ az iot hub invoke-device-method --hub-name <my-hub> --device-id <my-dev> --method-name SetTelemetryInterval --method-payload params.json { "payload": "Invalid direct method parameter: [object Object]", "status": 400 }
with params.json:
{ "payload": 2
and error from $node SimulatedDevice.js:
Direct method payload received: [object Object] Invalid interval response received in payload Response to method 'SetTelemetryInterval' sent successfully.
Just a final note, I've created a new method in the device that does not require a payload, and it's received and replies OK.
Hello,
How are you sending the payload? I believe you should serialize and send it as string. Here is a code to Serialize class to JSON in c# https://www.newtonsoft.com/json/help/html/SerializingJSON.htm
这篇关于`无效的直接方法参数:[object Object]`当使用`az iot hub invoke-device-method`时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!