-1
所以我有这样的代码:如何将数组数组转换为Flask中的对象数组?
@app.route("/")
def users():
try:
c, conn = connection()
c.execute(''' SELECT * FROM users ''')
rv = c.fetchall()
return jsonify(rv)
except Exception as e:
return(str(e))
和输出看起来是这样的:
[
[
1,
"Robert Soriano",
"[email protected]",
24
],
[
2,
"Charmaine Villar",
"[email protected]\r\n",
23
]
]
但自从我做了RESTful API,因此我希望它是在类似对象:
[
{
1,
"Robert Soriano",
"[email protected]",
24
},
{
2,
"Charmaine Villar",
"[email protected]\r\n",
23
}
]
我想是这样的:
try:
c, conn = connection()
c.execute(''' SELECT * FROM users ''')
rv = list(c.fetchall()) #converted to list
return jsonify(rv)
except Exception as e:
return(str(e))
但我仍然得到相同的输出。
我在这里错过了什么吗?在此先感谢
@McGrady谢谢。解决这个问题的最好方法是什么? – FewFlyBy
'{1,“Robert”}'是Python中的一个集合,不是字典或对象(用Javascript),我想你想生成一个Json字符串,看看http://www.json.org /或https://en.wikipedia.org/wiki/JSON – McGrady