简体   繁体   English

我如何获得下一个 json 密钥?

[英]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.

相关问题 给定 JSON 中的关键路径,如何访问 JSON 中的 $ref 并获取属性中的“类型”? - How do I access the $ref in the JSON and get the 'type' in properties, given a key path in JSON? 我如何获得下一个标签 - how do i get the next tag 在Python中解析JSON:如何在更改格式后让has_key()再次运行? - Parsing JSON in Python: how do I get has_key() working again after a change of format? 当密钥中有空格时,如何使用 python 和 Flask 获取 JSON 数据? - How do I get JSON data when the key has spaces in it using python and flask? 在解析JSON文件时,如何处理被导入的“ {key:value}”对的存在? - How do I handle the presence of `{key:value}' pairs that get imported as is when parsing a JSON file? "在 Python 中,如何获取字典中特定键的下一个和上一个键:值?" - In Python, How can I get the next and previous key:value of a particular key in a dictionary? 我如何获得异形的第二天日期时间 - How do i get the next day datetime in isoformate 我如何让这个程序替换最右边的 H 旁边的项目 - How do I get this program to replace the items next to the rightmost H 我如何进入该网站的下一个网页? - How do I get to the next web page on this site? 您好,如何修改以仅获取列表中的下一个节点? - hello, how do I modify to get the next node in the list only?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM