擅长:python、mysql、java
<p><code>date['device']</code>包含一个对象列表,因此应将其视为对象,并对其进行迭代:</p>
<pre><code>for element in data['device']:
if element['serial'] == '00000000762c1d3c':
print 'there'
print element['registered_id']
break
else:
print 'not there'
</code></pre>
<p>这是在使用不太为人所知的<code>for-else</code>构造:<a href="https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops" rel="nofollow noreferrer">https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops</a></p>