python - 如何将具有二进制对象的数组转换为 json 对象?
问题描述
我是 Flask 的新手。这是我在 Flask 中点击端点时得到的响应。我想将其转换为 JSON 对象。我使用 Redis DB 对用户进行排名。
[(b"{
'_id': ObjectId('611008325498c2b76a4f6b23'),
'name': 'Husmitha',
'email': 'husmitha@abc.com',
'password': 'Husmitha',
'district': 'Colombo'
}", 25000.0),...
(b"{
'_id': ObjectId('611014eb5498c2b76a4f6b25'),
'name': 'Kusal',
'email': 'kusal@abc.com',
'password': 'password',
'district': 'kandy'
}", 2000.0)]
这是我使用的代码。
@app.route("/getDetails", methods=["POST"])
def get_point_redis():
earn_gain = "Earn_gained"
user_earns = db.CropData.find()
print(user_earns)
for user in user_earns:
user["_id"] = str(user["userID"])
earnsbyUsr = user["earns"]
redisClient.zadd(earn_gain, {user["_id"]: earnsbyUsr})
print("Contents of the Redis sorted set with scores:")
response = redisClient.zrange(earn_gain, 0, -1, desc=True, withscores=True)
print(response)
for obj in response:
bObject = user["_id"]
return Response(
response= json.dumps({"message": json.loads(dumps(response))}),
status=200,
)
我究竟做错了什么?
解决方案
推荐阅读
- pytorch - fuser -v /dev/nvidia* 显示一个不使用 GPU 的进程
- xamarin.forms - MasterDetailPage 只导航第一次点击
- vb.net - 如何在 vb.net web api 项目中启用 CORS
- reactjs - 如何将嵌套对象的道具传递给组件?
- powershell - 受限模式下的 Powershell 和 Power cli
- spring-boot - 如何验证 sql DB 连接是否在 Spring Boot 应用程序中使用 ssl?
- mysql - 内部连接没有给出唯一值mysql
- java - mockito,当使用 when/thenReturn 设置模拟存根时出现异常
- python - 如何使用“特殊字符”保存/加载泡菜字典/列表
- seo - JSON-LD | 每页多个模式 | 构建网站的最佳方式是什么?