python解析多层次json并转成字典_将Python中的JSON解析为字典

A bit lost after much research. My code below parses the JSON to a dictionary I have thought using json load

response = json.load(MSW) # -->Will take a JSON String & Turn it into a python dict

Using the iteration below I return a series like this which is fine

{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

But how oh how do I access the 222.5 value. The above appears to just be one long string eg response[1] and not a dictionary structure at all.

In short all I need is the numerical value (which I assume is a part of that sting) so I can test conditions in the rest of my code. Is is a dictionary? With thanks as new and lost

解决方案

You have to use python syntax as follows:

>>> print response['swell']['components']['primary']['direction']

222.5

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值