Invalid JSON objects from Twitter API in Python -


i'm trying obtain data twitter apis. following code in python (i'm using twitterapi)

api = twitterapi(consumer_key, consumer_secret, access_token_key, access_token_secret) r = api.request('search/tweets', {'q':'pizza'}) item in r:         print(item) 

the code works , prints result. however, aren't valid json objects. actually, contains additional "u" character, example:

{u'contributors': none,  u'truncated': false,  u'text': u'rt  @pizzaminati: smile.\nyour laugh.\nyour crust.\nyour sauce.\nyour  cheese.\nyour toppings.\nyour jokes.\nyour weird faces.\nyour  teasing.\npi\u2026'... 

i've worked twitter libs in objective-c , never responds strange results that. can show me how valid json objects (i've tried twython , got same result)? , best way parse json objects in python? thank you.

i'm assuming you're using python 2.x

this notation python's way of displaying unicode strings.

this may clearer:

>>> type(u'hello world') <type 'unicode'> >>> type('hello world') <type 'str'> 

this should not problem if you're parsing object in python , doing post processing in python. if you're copying , pasting else, may bothering you.

unfortunately, json module doesn't have nice inbuilt way give strings instead of json, this stackoverflow answer might help


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -