python - 无法序列化 json 数组
问题描述
我对使用 API 有点陌生,并且在尝试 json.dumps api 响应时收到 graphconnection is not serializable 错误。响应看起来是一个 json 数组,但是,当我运行 Type(api_response) 时,没有任何输出。
任何帮助,将不胜感激。
我努力了Type(api_response)
api_response = api_instance.graph_user_group_members_list(group_id, content_type, accept,limit=limit, skip=skip, x_org_id=x_org_id)
#pprint(api_response)
data = json.dumps(api_response)
我想将 api_response 转换为 python dict 格式,以便我可以使用 json 值....
我收到此错误
TypeError: Object of type GraphConnection is not JSON serializable
如果我打印 api_response,这是输出
[{'_from': None, 'to': {'id': '', 'type': 'user'}}, {'_from': None,
'to': {'id': '', 'type': 'user'}}]
解决方案
我实际上能够通过使用([ob.dict for ob in api_response])找到解决方案。仍然认为我缺少一些关于 json.dumps 如何工作的知识。
推荐阅读
- python - 执行点击动作,处理当前页面并返回 StaleElementReference selenium Python
- android - 慢速 Kotlin 自动完成 Android Studio
- php - Laravel 日历调度器
- python - YamlValidationException:运行 rasa train 时无法验证“domain.yml”
- javascript - 如何运行 jQuery 预览上传按钮?
- amazon-ec2 - 安装了 OSSEC 的 aws 自动缩放 AMI
- javascript - 如何将重定向链接添加到 onclick Material ui 图标 - React
- javascript - 在输入字段上调度 Enter keydown 事件
- flutter - 状态改变时 Flutter OpenContainer 重建?
- c - 我从 CS50x 中提出了我自己版本的“现金”问题,我可以优化它吗?