把sqlalchemy对象转化成json数据类型

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
def to_json_all(msg: list):
data = []
if type(msg) == list:
for i in range(len(msg)):
temp_dict = {}
j = 0
for k, v in msg[i].__dict__.items():
if j > 0:
temp_dict[k] = v
j += 1

data.append(temp_dict)
else:
temp_dict = {}
j = 0
for k, v in msg.__dict__.items():
if j > 0:
temp_dict[k] = v
j += 1
data = temp_dict
return data