【发布时间】:2020-06-24 09:50:19
【问题描述】:
我有一个通过 cx_oracle 库运行的选择查询。此查询的输出存储为 dict 列表,需要保存在 json 文件中以供将来使用和迭代。
但此查询的输出具有“cx_oracleLOB 对象”,因此,我遇到错误“TypeError:LOB 类型的对象不是 JSON 可序列化”并且无法写入json 文件。请找到我的代码:
con = cx_Oracle.connect(***)
cursor = con.cursor()
cursor.execute(q)
col_names = [row[0] for row in cursor.description]
rv = cursor.fetchall()
json_data = []
for result in rv:
json_data.append(dict(zip(col_names, result)))
with open("result.json",'w')as fp:
fp.write(json.dumps(json_data))
sample output of selectquery:
[
{
"name": "abc",
"age": 10,
"skills": <cx_Oracle.LOBobjectat0x00000123>
},
{
"name": "def",
"age": 10,
"skills": <cx_Oracle.LOBobjectat0x000004456>
}
]
【问题讨论】:
标签: json blob python-3.6 cx-oracle