Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 列表到JSON对象_Python_Json - Fatal编程技术网

Python 列表到JSON对象

Python 列表到JSON对象,python,json,Python,Json,我收到了以下表格中的数据: ['{\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 "u

我收到了以下表格中的数据:

['{\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对象
,以便:

json_obj['data']['promotor']['instagram\u id']

我曾尝试使用
转储将
列表
转换为
JSON字符串
,然后使用
加载
,但没有效果


如果有任何帮助,我们将不胜感激。

您应该使用
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

谢谢你,瑞吉斯。我当时正在做
json.loads(data)
,遇到了一个错误,我需要提供一个
string
@Giri,这似乎应该是一个线索!