How to print particular JSON value in Python?

前端 未结 2 550
傲寒
傲寒 2020-12-16 17:16

So I have a Python code which returns a JSON string like this one:

\'{"X": "value1", "Y": "value2", "Z": [{&         


        
2条回答
  •  醉梦人生
    2020-12-16 17:57

    >>> import json
    >>> a = json.loads('{"X":"value1","Y":"value2","Z":[{"A":"value3","B":"value4"}]}')
    >>> a
    {'Y': 'value2', 'X': 'value1', 'Z': [{'A': 'value3', 'B': 'value4'}]}
    >>> a["Z"][0]["A"]
    'value3'
    

提交回复
热议问题