I'm fiddling with an API and this is the response i get:
{
"name1": {
},
"name2": {
"something1": 213,
"something2": [
{
"info1": 123,
"info2": 324
}
]
}
}
I've tried using
r.json()['name2']['something2']['info2'][0]
and
r.json()['name2']['something2'][0]
the first one gives me an error while the second one prints "something2" in its entirety, which i only need specific infos and values from there. How can I do that?
CodePudding user response:
I think you should use the following code
data = r.json()
data['name2']['something2'][0]['info2']
You need to put [0] after something2 because something2 is a list