Parse JSON with Python

后端 未结 2 1960
逝去的感伤
逝去的感伤 2021-01-03 13:25

I\'d like to parse

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

and end up with:

2条回答
  •  清歌不尽
    2021-01-03 13:46

    >>> 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
    

    Or use simplejson with older versions of Python.

提交回复
热议问题