So, I have this code to fetch JSON string from url
url = 'http://....'
response = urllib2.urlopen(rul)
string = response.read()
data = json.loads(string)
for x in data:
print x['foo']
The problem is x['foo']
, if tried to print it as seen above, I get this error.
Warning: Incorrect string value: '\xE4\xB8\xBA Co...' for column 'description' at row 1
If I use x['foo'].decode("utf-8")
I get this error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\u4e3a' in position 0: ordinal not in range(128)
If I try, encode('ascii', 'ignore').decode('ascii')
Then I get this error.
x['foo'].encode('ascii', 'ignore').decode('ascii') AttributeError: 'NoneType' object has no attribute 'encode'
Is there any way to fix this problem?