擅长:python、mysql、java
<p>您可以编写一个函数,它将获得所需的值:</p>
<pre><code>def dict_get(x,key,here=None):
x = x.copy()
if here is None: here = []
if x.get(key):
here.append(x.get(key))
x.pop(key)
else:
for i,j in x.items():
if isinstance(x[i],list): dict_get(x[i][0],key,here)
if isinstance(x[i],dict): dict_get(x[i],key,here)
return here
dict_get(a,'id')
['12345']
dict_get(a,'self')
['https://www.google.com', 'https://www.google.com']
dict_get(a,'name')
['beast']
</code></pre>
<p>您也可以调用任何想要的密钥:</p>
<p>数据</p>
<pre><code>a = {
"items": [
{
"id": "12345",
"links": {
"self": "https://www.google.com"
},
"name": "beast",
"type": "Device"
}
],
"links": {
"self": "https://www.google.com"
},
"paging": {
"count": 1,
"limit": 1,
"offset": 0,
"pages": 1
}
}
</code></pre>