1👍
Parse the JSON data with simplejson
module:
from django.utils.simplejson import loads
data = {"access_token": "oauth_token_secret=XXXXXXXXXXXX&oauth_token=YYYYYYYYYYY", "7200": null, "id": null} tokens = parse_qs(loads(data)['access_token'])
json_dict = loads(data)
access_token = json_dict['access_token']
Then use what Jan suggested to you to parse the query string stored in access_token
:
from urlparse import parse_qs
tokens = parse_qs(access_token)
print tokens['oauth_token_secret']
print tokens['oauth_token']
👤caio
0👍
For parsing the access_token
, you can use http://docs.python.org/library/urlparse.html#urlparse.parse_qs:
Parse a query string given as a string argument (data of type application/x-www-form-urlencoded). Data are returned as a dictionary. The dictionary keys are the unique query variable names and the values are lists of values for each name.
- [Answer]-Django view function does not seem to work
- [Answer]-How to get the array consisting of arrays containing the fields from the table row in Django QuerySet API?
Source:stackexchange.com