[英]How do I get the next json key?
There is such a json:有这样一个json:
{
"id": "1994",
"schedule": {
"1": {
"title": "Понедельник",
"schedule": {
"4": {
"1": {
Full: https://pastebin.com/wLX6D0w完整版: https : //pastebin.com/wLX6D0w
I output schedule['schedule']['1']['schedule'], but how do I get the next key (the json file can change, and the key value too. In this case, it is equal to 4)?我输出schedule['schedule']['1']['schedule'],但是我怎么得到下一个key(json文件可以改变,key值也可以。在这种情况下,它等于4) ?
Using an index?使用索引? How?
如何?
I found a solution.我找到了解决方案。 This is
schedule['schedule'][str(weekday_list.get(dayWeek))]['schedule'].keys()
这是
schedule['schedule'][str(weekday_list.get(dayWeek))]['schedule'].keys()
import json
jsn = {
"id": "1994",
"schedule": {
"1": {
"title": "LOL",
"schedule": {
"4": {
"1": {
}
}
}
}
}
}
# dumping jsn variable from !!!PYTHON!!! dict to string
step_one = json.dumps(jsn)
# loading dumped jsn variable from string to !!!JSON!!!
step_two = json.loads(step_one)
print(step_two['schedule']['1'])
print(step_two['schedule']['1']['schedule'])
print(step_two['schedule']['1']['schedule']['4'])
print(step_two['schedule']['1']['schedule']['4']['1'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.