5
我想要使用Python中的pyobc庫檢索表的行。pyodbc返回的行不是JSON可序列化
我能夠成功檢索表中的表和字段。現在我有一個表命名爲「apx_roomtypes」有如下數據,
然而,當我的pyodbc行追加到一個列表,然後嘗試列表轉儲到JSON我得到的錯誤
TypeError: (1, 'Standard', 'For 5 members', 123) is not JSON serializable
這裏是Python代碼:
class execute_query:
def GET(self,r):
web.header('Access-Control-Allow-Origin', '*')
web.header('Access-Control-Allow-Credentials', 'true')
cnxn = pyodbc.connect(connection_string)
data = []
cursor = cnxn.cursor()
query = web.input().query
cursor.execute(query)
rows = cursor.fetchall()
for row in rows:
data.append(row)
return json.dumps(data)
如何解決這個問題?
感謝您的鏈接兄弟,多數民衆贊成我需要 – Sajeetharan
'列表(行)'應該做的伎倆沒有生成器表達式。 – kindall
Thx @kindall - 已應用。 –