python - 如何在python中将JSON字符串转换为整数?
问题描述
如何从这个 json 将 year 和 isbn 转换为整数?
({
"title": "The Notebook",
"author": "Nicholas Sparks",
"year": "1996",
"isbn": "0553816713"
})
解决方案
您可以简单地使用相应的 int 值更新这些值
data = {
"title": "The Notebook",
"author": "Nicholas Sparks",
"year": "1996",
"isbn": "0553816713"
}
data["year"] = int(data["year"])
data["isbn"] = int(data["isbn"])
print(data)
OUT: {'title': 'The Notebook', 'author': 'Nicholas Sparks', 'year': 1996, 'isbn': 553816713}
推荐阅读
- python - 从一个字典列表中提取值到另一个
- javascript - 在这个函数中回调是如何执行的?
- node.js - 从 ChildProcess 创建一个转换流
- sorting - d3 气泡图:特定的排序和布局
- react-native - 在本机反应中有条件地设置初始路由
- botframework - 在 QnA Maker 知识库中没有该问题(新问题)的答案时保存问题
- mysql - 使用 Eloquent 将数据插入到两个具有关系的不同表中
- python - 如何将多次迭代的pyomo解决方案(仅包括参数、目标和变量)写入excel/csv文件?
- c - 如何在编码器 x264 和解码器 libavcodec 中找到量化的变换系数?
- terraform - Terraform 可选嵌套对象变量