python - 如何将 Python 数字列表转换为 json 对象
问题描述
我想将 python 数字列表转换为 json 对象。输入:
input is a number like 22
期望的输出:
{
"budget" : 22
}
解决方案
首先,“有效”json 对象中不能有重复的键。
您最好的选择是将您的列表转换为 Python 字典,然后将其转换为 JSON 对象:
import json
my_list = [22, 30, 44, 55] # Your starting list
python_dict = {"budget": my_list} # Python dict
json_obj = json.dumps(python_dict) # Convert python dict to JSON obj
推荐阅读
- c# - C# - 从 Active Directory 返回自定义安全组
- c++ - 是否有任何任务栏 API 可以立即应用注册表更改?
- python - 搜索输入值小于下一个索引列值的 pandas 数据框列
- java - 使用 WindowsDriver 时,有没有办法在 Appium/Selenium 节点上上传文件?
- python - 即使在 pip3 安装之后,Selenium “没有名为‘selenium’的模块”
- python - 如何在 Python 中验证 Google OAuth 授权服务器的响应?
- javascript - 如何传递闪亮树值以在闪亮中下拉输入
- ios - 创建 IPA:pom.xml 上的配置文件
- javascript - 如何在表 td 标记的循环中显示反应变量值
- javascript - 如何在javascript中用正则表达式替换特定出现的字符串