数据例如:
data = { "duringTime": 401, "timesPerDay": 10000, "device":{ "appid":1, "appName":"com.planet2345.com", "appName2":"com.planet2345.com2" } }
代码如下:
key_list=[] #获取json中包含的所有键(包括嵌套字典) def getJsonKey(json_data): #递归获取字典中所有key for key in json_data.keys(): if type(json_data[key])==type({}): getJsonKey(json_data[key]) key_list.append(key) return key_list print(getJsonKey(data1))
结果如下: