我正在以这种形式返回数据:
['{\n "data": {\n "promoter": {\n "instagram_id": 123,\n "instagram_name": "user",\n "instagram_token": "\\"123\\"",\n "location": "sydney",\n "profile_pic": "profile/pic.jpg",\n "user_id": 1,\n "username": "my_user_name"\n },\n "success": true\n }\n}']
我很困惑如何将其转换为JSON object
以便我可以这样做:
json_obj['data']['promoter']['instagram_id']
我尝试使用list
将JSON String
转换为dumps
,然后使用loads
,但无济于事。
对此有任何帮助将不胜感激。
答案 0 :(得分:3)
您应该只使用json.loads
转换列表的第一个元素。演示:
>>> data = ['{\n "data": {\n "promoter": {\n "instagram_id": 123,\n "instagram_name": "user",\n "instagram_token": "\\"123\\"",\n "location": "sydney",\n "profile_pic": "profile/pic.jpg",\n "user_id": 1,\n "username": "my_user_name"\n },\n "success": true\n }\n}']
>>> import json
>>> json_obj = json.loads(data[0])
>>> json_obj['data']['promoter']['instagram_id']
123