<p>在Python中,<code>json.loads</code>将json对象映射到Python字典,并将<code>Arrays</code>映射到<code>list</code>,因此可以像使用常规Python <code>dict</code>和<code>list</code>结构一样执行进一步的操作。</p>
<p>以下是如何使用<a href="https://www.google.com.ua/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CDEQFjAA&url=http%3A%2F%2Fwww.python-requests.org%2F&ei=xQFlUobnOcj74QT0roH4CA&usg=AFQjCNENpbVzvKfwo4BGNPn6-mOyfYNDpg&sig2=5Ms2N366vADzpUDqpfpHBg&bvm=bv.54934254,d.bGE" rel="nofollow">requests</a>和<code>lamdbas</code>来完成此任务:</p>
<pre><code> import json
import requests
response = requests.get("http://eu.battle.net/api/wow/realm/status")
json_data = json.loads(response.text)
# loop through the list of realms to find the one you need (realm_name)
get_realm = lambda realm_name, jd: [r for r in jd['realms']
if r['name'] == realm_name]
# extract data you need, if there is a match in the list of realms,
# return None otherwise
get_your_data = lambda realm: (
realm[0]['name'],
realm[0]['wintergrasp']['controlling-faction']
) if realm else None
print get_your_data(get_realm('Silvermoon', json_data))
</code></pre>