不行
輸出的資料json仍不能接收
我再次進行轉換 語法修改如下
import sqlite3
import sys
import json
import datetime
#datetime.datetime.strptime('24052010', '%d%m%Y').date()
##tm = row.datetime.strptime("%Y-%m-%d %H:%M:%S")
db = sqlite3.connect('flag.db')
cursor = db.cursor()
cursor.execute('SELECT datetime as date1,f1,f2 FROM data ORDER BY datetime asc limit 10')
user1 = cursor.fetchone() #retrieve the first row
all_rows = cursor.fetchall()
rowarray_list = []
t = ('datetime','f1','f2')
rowarray_list.append(t)
for row in all_rows:
print('{0} : {1}, {2}'.format(row[0], row[1], row[2]))
t = (datetime.datetime.strptime(row[0], '%Y-%m-%d %H:%M:%S').date(),row[1],row[2])
rowarray_list.append(t)
j = json.dumps(rowarray_list)
輸出畫面如下
2011-02-08 04:36:15 : 31.6, NULL
2011-02-09 01:37:05 : 30.6, 81.0
2011-02-09 19:02:09 : 22.1, 77.0
2011-02-10 18:21:47 : 21.5, 80.0
2011-02-11 08:42:04 : 23.2, 85.0
2011-02-11 18:32:01 : 28.1, 80.0
2011-02-12 09:42:05 : 31.6, 82.0
2011-02-12 17:42:05 : 25.9, 85.0
2011-02-12 21:42:05 : 22.9, 80.0
Traceback (most recent call last):
File "flag3.py", line 20, in <module>
j = json.dumps(rowarray_list)
File "c:\Python34\lib\json\__init__.py", line 230, in dumps
return _default_encoder.encode(obj)
File "c:\Python34\lib\json\encoder.py", line 192, in encode
chunks = self.iterencode(o, _one_shot=True)
File "c:\Python34\lib\json\encoder.py", line 250, in iterencode
return _iterencode(o, 0)
File "c:\Python34\lib\json\encoder.py", line 173, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: datetime.date(2011, 2,

is not JSON serializable