gpt4 book ai didi

python - 从 json 中删除\r

转载 作者:行者123 更新时间:2023-12-01 09:29:21 25 4
gpt4 key购买 nike

返回 json 对象时如何删除\r?我尝试使用 Flask 创建一个 API,但 API 返回的 json 对象始终包含\r ,如下所示。

{
"data": [
{
"CLOSE\r": "1.16386\r",
"DTYYYYMMDD": "20170726",
"HIGH": "1.1639",
"LOW": "1.16386",
"OPEN": "1.16389",
"TIME": "0705"
},
{
"CLOSE\r": "1.16385\r",
"DTYYYYMMDD": "20170726",
"HIGH": "1.16387",
"LOW": "1.16385",
"OPEN": "1.16386",
"TIME": "0706"
}
]}

我的Python代码看起来像

class GetPriceData(Resource):
def get(self, date): # param is pulled from url string
conn = e.connect()
query = conn.execute("select * from pricedata where DTYYYYMMDD='%s'" % date.upper())
result = {'data': [dict(zip(tuple(query.keys()), i)) for i in query.cursor]}
return result

最佳答案

您可以尝试修改结果分配行:

result = {'data': [dict(zip(tuple(query.keys().replace("\r","")), i.replace("\r",""))) for i in query.cursor]}

关于python - 从 json 中删除\r,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50101186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com