我期待一個JSON味精變量與Python沿着這些線路進行解析,通過MQTT進來:的Python尋找在JSON
{"OPTION1": "0", "OPTION2": "50", "OPTION3": "0", "OPTION4": "0"}
根據情況的不同,這些選項可能會或可能不會進行解析通過的Python進入JSON MSG,正因爲如此,它可能最終尋找爲:
{"OPTION1": "0", "OPTION3": "0", "OPTION4": "0"}
並且因此跳過OPTION2和它完全值。
爲了避免我的腳本borking了我,我就在想掃描如果選項是那裏第一次,在設置前,像這樣:
if data['OPTION1']:
>do something here<
else:
continue
然而,這似乎並沒有工作,它想出:
File "listen-mqtt.py", line 28
continue
SyntaxError: 'continue' not properly in loop
任何幫助將非常感激!謝謝。
'pass'就是你要找的(不是'繼續') –
'else'子句是不必要的。 https://docs.python.org/3/tutorial/controlflow.html?highlight=continue – tanglong