当前位置:网站首页>【记录】把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)
边栏推荐
猜你喜欢
随机推荐
数组与字符串15-最大连续1的个数
9. Please introduce the class loading process, what is the parent delegation model?
什么是参数化设计,通过实操了解一下? | SOLIDWORKS 操作视频
二分查找6 - 寻找峰值
借助ginput函数在figure窗口实时读取、展示多条曲线的坐标值
2021-03-22
ZEMAX | 如何创建复杂的非序列物体
芯片解密工作应该具备哪些条件?唯样商城
2. What is the difference between Exception and Error?
g++ parameter description
VS2022 encapsulates static libraries and calls static libraries under window
中空编码器的作用——唯样商城
3D游戏建模师在国内的真实现状,想转行,先来看看!
剑指 Offer II 001. 整数除法
g++参数说明
3. What is the difference between final, finally, and finalize?
关于芯片你了解吗?
【面试准备】游戏开发中的几个岗位分别做什么&考察侧重点
三、final、finally、 finalize有什么不同?
六、对比Vector、ArrayList、LinkedList有何区别?(设计、性能、安全)