So I've got some lines from a website to a variable using json, and the code looks like this:
with urllib.request.urlopen("someurl") as url:
data = json.loads(url.read().decode())
Now, this data contains text like:
"Dog": "Woof"
"Cat": "Meow"
and so on.. How do I put this data so the Key of the dictionary would be the animal and the value would be the sound?
json.loads() already did that for you. try accessing data['Dog'] and you will get 'Woof'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.