python数据表数据与JSON数据相互转化

20190116164347961.png

1. 将从数据表读取的数据转化成JSON

reslist = ms.ExecQuery("select * from mytable01")
req = []
for row in reslist:
    d = collections.OrderedDict()
    d['no'] = row[0]
    d['str'] = row[1]
    req.append(d)
rspstr = json.dumps(req)

2.从JSON输入插入到数据表

# 将json数据插入到数据库
x = len(data)
i = 0
while i < x:
    F = [data[i]['no'],data[i]['str']]

    # 插入数据
    newsql="update mytable01 set str = " + "'" + F[1] + "' where no = " + "'" + str(F[0]) + "'" + ";"

 

 

 

你可能感兴趣的:(python,python,json,数据表,转换,序列化)