Collecting a value from Json
本问题已经有最佳答案,请猛点这里访问。
我从一个脚本中收集了这个JSON数据,想知道如何解析数据以获得id属性。甚至不知道该查什么。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | { "status":"success", "data": [ { "notes": [], "handles": { "twitter": [ { "networkinstance":"twitter", "Uid":"fefewf32ff32f232f3f", "id":"243425324242", "@class":"Provider" } ] }, "id":"g43g5434g43f2f3", "tags": [] } ] } |
使用
1 2 3 4 | import json json_result = json.loads(json_string) id = json_result['data'][0]['id'] |
演示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | >>> 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' |