2017-07-20 116 views
0

我想發送一個curl命令到網絡服務器來控制我家裏的設備。 Web服務器包含以下JSON數據:無法使用curl發送JSON數據到網絡服務器

{"result":1, "error":null, "id":0, "data":{"vid":2, "did":4, "device_type":"airconditioner", "default_name":"Air Conditioner Settings", "tags":"aircon", "is_sensor":1, "is_actuator":1, "is_silent":0, "has_time_series":0, "has_subdevice_count":0, "has_state":0, "gid":"0", "guid":"xxxx", "node":"yyy", "meta":{}, "shortName":"", "subDevices":{}, "last_data":{"DA":{"amOn":false, "tempTarget":22, "mode":1, "fanSpeed":0, "enabledZones":[1,1,0,0,0,0,0,0]}, "timestamp":1500523622862}} 

使用curl我可以把下面的PUT命令,打開設備:

curl -v -H "Accept: application/json" -H "Content-Type: application/json" -X PUT -d '{"DA":{"amOn":"true"}}' https://actron.ninja.is/rest/v0/device/xxxx?user_access_token=zzzz 

但是我被困在發送PUT命令更改號碼在enabledZones數組中。

我曾嘗試以下沒有成功命令的許多變化:

curl -v -H "Accept: application/json" -H "Content-Type: application/json" -X PUT -d '{"DA":{"enabledZones[1]":"0"}}' https://actron.ninja.is/rest/v0/device/xxxx?user_access_token=zzzz 

任何建議將非常讚賞

回答

0

我認爲你是在發送JSON不正確陣列的要求。要用0更新數組元素1,您需要使用"enabledZones":[1,0,0,0,0,0,0,0]

請參閱若跌破curl命令工作

curl -v -H "Accept: application/json" -H "Content-Type: application/json" -X PUT -d '{"DA":{"enabledZones":[1,0,0,0,0,0,0,0]}}' https://actron.ninja.is/rest/v0/device/xxxx?user_access_token=zzzz 
相關問題