Skip to content Skip to sidebar Skip to footer

Json And Non-English Languages

I'm new to Python and trying hard to learn it. I was trying to save tweets by using Tweepy and because my query is in 'Arabic' the results seems to be strange like this: 'created

Solution 1:

The problem is that by default json.dumps() encodes any non ASCII characters using escaped Unicode notation, which optional in the JSON specification. By passing ensure_ascii=False to dumps(), this will disable this feature.

The second problem you'll have once you fixed the main problem, is you'll try to print list. Python will the print a representation of the list, including representations of the data inside it. This means that the data includes literals and a safe way to print data.

For strings, this means that the object is printed with quotes and any non-ascii characters are printed as Unicode escape sequences.

Try:

json_strings = [json.dumps(json_obj, ensure_ascii=False) for json_obj in searched_tweets]  
for tweet in json_strings:
    print(tweet)

Post a Comment for "Json And Non-English Languages"