0

I am new to Django and I am using twython library for twitter search. I am getting json file where 'u' character is added before to key for eg.

{u'search_metadata': {u'count': 15, u'completed_in': 0.028, u'max_id_str': u'640844327904800768', u'since_id_str': u'0', u'refresh_url': u'?since_id=640844327904800768&q=kjitu9&include_entities=1', u'since_id': 0, u'query': u'kji', u'max_id': 640844327904800768}, u'statuses': [{u'contributors': None, u'truncated': False, u'text': u'@aaa I just thought seeing as you were setting goals it may help you, would love to know your thoughts - http://t.co/dEjAct', u'is_quote_status': False, u'in_reply_to_status_id': None, u'id': 640844327904800768, u'favorite_count': 0, u'source': u'mention\xa0', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [{u'id': 363525191, u'indices': [0, 7], u'id_str': u'363525191', u'screen_name': u'kjit', u'name': u'Ji'}], u'hashtags': [], u'urls': [{u'url': u'http://t.co/dEjActDuCX', u'indices': [108, 130], u'expanded_url': u'http://freedawn.com', u'display_url': u'freedawn.com'}]}

parser = Parser()
twitter = Twython(settings.TWITTER_CONSUMER_KEY,
    settings.TWITTER_CONSUMER_SECRET,
    settings.TWITTER_OAUTH_TOKEN,
    settings.TWITTER_OAUTH_TOKEN_SECRET)
try:
    user_timeline = twitter.search(q=settings.TWITTER_USER)
    print user_timeline
except TwythonError as e:
    return {"latest_tweet": e}
print user_timeline
jeet
  • 27
  • 6
  • That's not an 'arbitrary character', it's telling you that you're working with Unicode strings. See https://docs.python.org/2/howto/unicode.html – bgporter Sep 08 '15 at 15:18
  • @bgporter Is not a duplicated question, this user doesn't get the difference between a json string and a python dictionary. – diegueus9 Sep 08 '15 at 15:22
  • The problem that's stated is "'u' character is added before to key", which smells to me more like "I don't get Unicode" than "I don't get `dict`s". If the OP rewrites to push toward your interpretation, I'll vote to reopen. – bgporter Sep 08 '15 at 15:30

1 Answers1

1

That's not a json string, that's a python dictionary, they look pretty similar but aren't the same thing. You could use the json module if you need a json, or use it as it gets.

diegueus9
  • 29,351
  • 16
  • 62
  • 74