数组的数组的数组类型

2024-09-24 22:23:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我的FlaskAPI返回的数据很难在前端的JS中使用

以下是端点:

class BilagList(Resource):
    def get(self):
        connection = sqlite3.connect('data.db')
        cursor = connection.cursor()
        query = "SELECT * FROM bilag"
        result = cursor.execute(query)
        row = result.fetchall()
        return {'bilag': row}

结果如下:

{
"bilag": 
[
[1, "description", "price", null], 
[2, "2description", "2price", null], 
[22, "Her er Serenas f\u00f8rste bilag!", "1000", "Serena"], 
[23, "Her er Admins f\u00f8rste bilag!", "1000", "admin"]
]
} 

我只想:

[1, "description", "price", null], 
[2, "2description", "2price", null], 
[22, "Her er Serenas f\u00f8rste bilag!", "1000", "Serena"], 
[23, "Her er Admins f\u00f8rste bilag!", "1000", "admin"]

然后我就可以用js在数组中循环

我可以删除 { “比拉格”: }

,只返回第一排,但我如何摆脱最后一对[]? 有什么好的理由不这样做吗

克瑞斯滕酒店


Tags: descriptionresultconnectionquerynullpricecursorrow