On Dec 27, 2017 1:02 PM, "tango ward" <tangoward15@gmail.com> wrote:
Follow up question. Apologies for the continuation.I tried integrating the API from OpenDOTA https://api.opendota.com/api/heroes .my code:import requestsimport jsonurl = requests.get('https://api.opendota.com/api/heroes ')res = url.json()when I typed in 'res' in my terminal, it returns a List of dictionaries. Now, is it possible to turn this list to a dictionary? Apologies for the confusion, I am confuse as well.
The terms you are looking for are serialization (converting Python objects to JSON) and deserialization (converting JSON to Python objects).
If you're using requests, and you can successfully run the .json() method, then you successfully converted the JSON to a native Python structure.
In this case, you are requesting a list of heroes, so you received a list back. You'll need to find the hero you want in the list using the standard methods of working with Python lists, access that element, and then you'll have access to the dict for that hero.
There is probably a way to get a single dict for a specific hero from the API, but I'm not familiar with their API structure. You'll need to revert to their API documentation to determine the correct URL structure.
-James
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUVLzj8%2BeZvwJo_tPGLy7-f33Nqwv4yf8v8GA3HdwBNEA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment