我的flask API返回的数据很难在前端的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遍历数组。
我可以删除 { “ bilag”: }
,只需返回行,但是如何摆脱最后一对[]? 而且有什么充分的理由不这样做吗?
BR Kresten