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。