Collecting a value from Json

This question already has an answer here:

  • Parsing values from a JSON file? 7 answers

  • After decoding with the json module, this is just a dictionary containing lists and strings and other dictionaries:

    import json
    
    json_result = json.loads(json_string)
    id = json_result['data'][0]['id']
    

    Demo:

    >>> import json
    >>> sample = '''
    ... {
    ...     "status": "success",
    ...     "data": [
    ...         {
    ...             "notes": [],
    ...             "handles": {
    ...                 "twitter": [
    ...                     {
    ...                         "networkinstance": "twitter",
    ...                         "Uid": "fefewf32ff32f232f3f",
    ...                         "id": "243425324242",
    ...                         "@class": "Provider"
    ...                     }
    ...                 ]
    ...             },
    ...             "id": "g43g5434g43f2f3",
    ...             "tags": []
    ...         }
    ...     ]
    ... }
    ... '''
    >>> json_result = json.loads(sample)
    >>> json_result['data'][0]['id']
    u'g43g5434g43f2f3'
    
    链接地址: http://www.djcxy.com/p/38048.html

    上一篇: 用Python写入json文件

    下一篇: 从Json收集一个值