What I want to do is to get Json data out as a list (or array) with Python, I tried several times but didn't work. My json data is like this:
{
"status":"OK",
"List":{
"stuff":[{
"id":"326",
"name":"a",
"url":"autob-fulla.tgz",
},{
"id":"327",
"name":"b",
"url":"auto-fullb.tgz",
},{
"id":"328",
"name":"c",
"url":"auto-fullc.tgz",
}]
}
}
I want to return all the value of "id". Now my code is like this:
import json
def retrieve():
print('retrieving results...')
testQueueID = '1';
base_url1 = 'http://localhost:8080/stuff'
conn = Connection(base_url1, username='admin', password='admin')
resp = conn.request_get("", args={}, headers={'content-type':'application/xml', 'accept':'application/xml'})
decoded_json = json.loads(json.dumps(resp, sort_keys=True, indent=4, skipkeys=True))
return decoded_json
json.dumpshere -json.loads()should be all you need.