擅长:python、mysql、java
<p>您的<code>payload</code>非常复杂,不需要用引号将其括起来,因为它可以被视为<code>dict</code>,而且您的<code>targetTemp</code>被视为字符串这就是为什么您看不到实际值。在</p>
<p>为了简单起见,您可能需要查看<a href="https://pyformat.info/" rel="nofollow noreferrer">Python string formatting</a>。在</p>
<p>你想怎么做就怎么做</p>
<pre><code>import json
targetTemp = 17
payload = {
"nodes": [{
"attributes": {
"targetHeatTemperature": {
"targetValue": targetTemp
}
}
}]
}
print(json.dumps(payload))
# output,
{"nodes": [{"attributes": {"targetHeatTemperature": {"targetValue": 17}}}]}
</code></pre>
<p>请注意,您还可以使用<a href="https://jsonlint.com/" rel="nofollow noreferrer">JSON Validators</a>来确保json对象的格式正确(这就是我用来格式化您提供的<code>JSON</code>)的方法</p>