Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x “我怎样才能得到dict”;“当前”;通过Python和pytest_Python 3.x - Fatal编程技术网

Python 3.x “我怎样才能得到dict”;“当前”;通过Python和pytest

Python 3.x “我怎样才能得到dict”;“当前”;通过Python和pytest,python-3.x,Python 3.x,现在我写了这个代码 r = requests.get(BET.format()) a = json.loads(r.text) print(a) 在那里我收到了所有json响应。然后需要使用python和pytest获取“current”以解析其中的值: { "command": "bet", "status": "ok", "game": { &quo

现在我写了这个代码

r = requests.get(BET.format())
 a = json.loads(r.text)
print(a)
在那里我收到了所有json响应。然后需要使用python和pytest获取“current”以解析其中的值:

{
    "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
                ]

您可以使用
a['game']['current']
访问与上面dict文本中的
“current”
键相关的值,这是否回答了您的问题?你知道如何使用字典吗?你试过和这个人合作吗?发生了什么事?另外,请注意,请求有一个方法可以将主体解析为JSON。