【发布时间】:2014-06-30 12:25:31
【问题描述】:
经过大量研究后有点失落。我下面的代码将 JSON 解析为我认为使用 json load 的字典
response = json.load(MSW) # -->Will take a JSON String & Turn it into a python dict
使用下面的迭代,我会返回一个这样的序列,这很好
{u'swell': {u'components': {u'primary': {u'direction': 222.5}}}}
{u'swell': {u'components': {u'primary': {u'direction': 221.94}}}}
ourResult = response
for rs in ourResult:
print rs
但是我如何访问 222.5 值。以上似乎只是一个长字符串,例如 response[1] 而根本不是字典结构。
简而言之,我只需要数值(我假设它是该刺的一部分),因此我可以在其余代码中测试条件。是字典吗?感谢新的和失去的
【问题讨论】:
-
这个问题似乎不是关于解析 JSON,而是关于导航嵌套的 Python 字典。
标签: python json dictionary