使用Python解析JSON [英] Parse JSON with Python

查看:349
本文介绍了使用Python解析JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想解析

{"ticker":{"high":31.9099,"low":22.5,"vol":108468,"buy":29.61,"sell":30,"last":29.61}}

最后得到:

last = 29.61

但是我不知道从哪里开始解析python:(

but I don't know where to start parsing python :(

推荐答案

>>> text = '''{"ticker":{"high":31.9099,"low":22.5,"vol":108468,"buy":29.61,"sell":30,"last":29.61}}'''
>>> json.loads(text)
{u'ticker': {u'sell': 30, u'buy': 29.609999999999999, u'last': 29.609999999999999, u'vol': 108468, u'high': 31.9099, u'low': 22.5}}
>>> json.loads(text)[u'ticker'][u'last']
29.609999999999999

或者将simplejson与旧版Python一起使用.

Or use simplejson with older versions of Python.

这篇关于使用Python解析JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆