当前位置:网站首页>【记录】把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)
边栏推荐
猜你喜欢

【3D建模制作技巧分享】ZBrush快捷键如何设置

VS2022 encapsulates static libraries and calls static libraries under window

SolidWorks 操作视频 | 流体分析结果演示

VS2022 encapsulation under Windows dynamic library and dynamic library calls

2021-04-30

ZBrush+Substance制作蜥蜴巫婆医生!

大佬!Maya+ZBrush+Substance制作泰坦野兽全流程!

POE交换机全方位解读(中)

二分查找3 - 猜数字大小

全球一流医疗技术公司如何最大程度提高设计工作效率 | SOLIDWORKS 产品探索
随机推荐
2021-03-22
Practice of MySql's Sql statement (try how many you can write)
二分查找6 - 寻找峰值
Phase Vocoder的补充完善,Matlab音频变速不变调、变调不变速
VCC(电源)和 GND(地)之间电容的作用
C语言中打印字符数组出现乱码的问题(烫烫烫)
设备树(devicetree)-dts语法
数组与字符串11-反转字符串
PCB设计经验之模拟电路和数字电路区别为何那么大
3. What is the difference between final, finally, and finalize?
快速的将结构体各成员清零
三、final、finally、 finalize有什么不同?
2021-03-22
memblock
Dynamic adjustment of web theme (2) Extraction
3D建模:做什么副业在家就能月入1W?
【C语言】二分查找
ucosII OSMemCreate()函数的解析
IP数据包的格式(1)
【C语言】输出100~200之间的素数/质数(3种方法)