小编The*_*Kid的帖子

Python请求获取JSON

这是我的要求。

h="API-AUTHENTICATION:key:secret"
r=requests.get("https://URL", h)
Run Code Online (Sandbox Code Playgroud)

这是回应: <Response [200]>

如果我打印请求的纯文本,(print(r.text))我会得到:

{
    "status": "OK",
    "data": [
        {
            "sort": 1,
            "parent_name": "Stocktake Demo",
            "timetables": [
                {
                    "active": 1,
                    "from_date": "Nov 01, 2019",
                    "timetable_data": {
                        "monday": [
                            {
                                "to": "23:59",
                                "from": "00:00"
                            }
                        ],
                        "tuesday": [
                            {
                                "to": "23:59",
                                "from": "00:00"
                            }
                        ],
                        "friday": [
                            {
                                "to": "23:59",
                                "from": "00:00"
                            }
                        ],
                        "wednesday": [
                            {
                                "to": "23:59",
                                "from": "00:00"
                            }
                        ],
                        "thursday": [
                            {
                                "to": "23:59",
                                "from": "00:00"
                            }
                        ],
                        "sunday": [
                            { …
Run Code Online (Sandbox Code Playgroud)

python iteration dictionary

5
推荐指数
1
解决办法
2万
查看次数

Python 上具有嵌套字典深度的所有键

样本输入:

a = {
"key1": 1,
"key2": {
        "key3": 1,
        "key4": {
                "key5": 4
            }
        }
}
Run Code Online (Sandbox Code Playgroud)

示例输出:

key1 1
key2 1
key3 2
key4 2
key5 3
Run Code Online (Sandbox Code Playgroud)

如何遍历此嵌套字典的每个元素并打印每个单独元素的深度?

python dictionary nested

1
推荐指数
2
解决办法
485
查看次数

标签 统计

dictionary ×2

python ×2

iteration ×1

nested ×1