Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.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_List - Fatal编程技术网

Python中JSON数组名称的更改

Python中JSON数组名称的更改,python,json,list,Python,Json,List,我需要将这个JSON开头的JSON数组的名称更改为Python中的“数据”。现在我只是接收并打印JSON,如下所示: c = db.cursor() c.execute('select * from stuff') return json.dumps(c.fetchall()) 以下是JSON: [ { status: "F", id_num: "001", }, { status: "T",

我需要将这个JSON开头的JSON数组的名称更改为Python中的“数据”。现在我只是接收并打印JSON,如下所示:

c = db.cursor()
c.execute('select * from stuff')
return json.dumps(c.fetchall())
以下是JSON:

[
      {
           status: "F",
           id_num: "001",
      },
      {
           status: "T",
           id_num: "002",
      },
      {
           status: "T",
           id_num: "003",
      }
]

在表示数组的第一个方括号前插入
“数据”:
需要做什么?

只需将列表包装到一个新字典中:

return json.dumps({'data': c.fetchall()})

您没有更改名称。您正在将此列表放入另一本词典中。您的确切意思是什么?之后它将不是有效的json。如果这样做,则需要
{'data':数组}
。这可以接受吗?哇,我完全错过了。这就解决了问题。谢谢你的帮助。