当前位置:网站首页>【记录】把json的所有key转换成小写
【记录】把json的所有key转换成小写
2022-08-03 05:26:00 【IT界的测试混子】
import json
d = '''{ "Type": "Abc", "Id": "NO_ID", "IntId": -1, "Hashcode": 54321, "Rect": { "Width": 1234, "Height": 222, "Left": 0, "Top": 0 }, "Visible": true, "Enabled": true, "Clickable": false, "Tag": "", "Desc": "", "Children": [ { "Type": "android.widget.LinearLayout", "Id": "NO_ID", "IntId": -1, "Hashcode": 12345, "Rect": { "Width": 1234, "Height": 2220, "Left": 0, "Top": 0 }, "Visible": true, "Enabled": true, "Clickable": false, "Tag": "", "Desc": "", "Children": [ { "Type": "android.view.ViewStub", "Id": "01234", "IntId": 2314, "Hashcode": 22222, "Rect": { "Width": 0, "Height": 0, "Left": 0, "Top": 0 }, "Visible": false, "Enabled": true, "Clickable": false, "Tag": "", "Desc": "", "Children": [] } ] } ] }'''
def change_key_lower(d):
if isinstance(d,dict):
for i in list(d.keys()):
if isinstance(d[i], dict):
change_key_lower(d[i])
if isinstance(d[i],list):
for j in d[i]:
if isinstance(j, dict):
change_key_lower(j)
d[i.lower()] = d.pop(i)
if __name__ == '__main__':
d = json.loads(d)
res = change_key_lower(d)
边栏推荐
猜你喜欢
How the world's leading medical technology company maximizes design productivity | SOLIDWORKS Product Exploration
二分查找5 - 第一个错误的版本
SolidWorks 操作视频 | 隐藏高手必备工具Defeature,让设计隐藏更彻底
二层交换机,三层交换机,路由器内容总结记录
ZEMAX | 绘图分辨率结果对光线追迹的影响
VS2022 encapsulates static libraries and calls static libraries under window
采用Trench肖特基二极管,实现功率密度的显著提升
内网渗透信息收集
数组与字符串15-最大连续1的个数
2021-03-22
随机推荐
IP数据包的格式(1)
How the world's leading medical technology company maximizes design productivity | SOLIDWORKS Product Exploration
ZEMAX | 探究 OpticStudio 偏振分析功能
SolidWorks 操作视频 | 隐藏高手必备工具Defeature,让设计隐藏更彻底
MySql的Sql语句的练习(试试你能写出来几道呢)
3. What is the difference between final, finally, and finalize?
【面试准备】游戏开发中的几个岗位分别做什么&考察侧重点
电子元器件的分类有哪些?
2021-03-22
MATLAB给多组条形图添加误差棒
次世代建模到底需要哪些美术基础
关于C语言中getchar()函数的用法
数组与字符串9-翻转字符串里的单词
二分查找4 - 搜索旋转排序数组
003_旭日X3派初探:利用无线串口通信控制舵机
VCC(电源)和 GND(地)之间电容的作用
A.1#【内存管理】——1.1.2 zone: struct zone
classpath:与classpath*的比较
内网渗透信息收集
二分查找6 - 寻找峰值