首页 > 解决方案 > 如何通过 Python 和 pytest 获取 dict “Current”

问题描述

现在我写了这段代码

r = requests.get(BET.format())
 a = json.loads(r.text)
print(a)

我收到所有 json 响应的地方。而不是需要获取“当前”来解析值,使用 python 和 pytest:

{
    "command": "bet",
    "status": "ok",
    "game": {
        "current": {
            "lines": 25,
            "bet": 10,
            "state": "idle",
            "transitions": [
                "bet"
            ]
        },
        "symbols": {
            "symbols": [
                [
                    2,
                    2,
                    5
                ],
                [
                    2,
                    2,
                    10
                ],
                [
                    9,
                    9,
                    9
                ],
                [
                    6,
                    2,
                    2
                ],
                [
                    6,
                    5,
                    8
                ]

标签: python-3.x

解决方案


"current"您可以使用上面的 dict 文字访问与键关联的值a['game']['current']


推荐阅读