I am trying to return JSON from the API service from musicbrainz, the returned data for some songs have unicode characters which I am having trouble converting them to regular symbols etc. Kindly let me know what I should be doing here.
JSON:
{
"status": "ok",
"results": [{
"recordings": [{
"duration": 402,
"tracks": [{
"duration": 402,
"position": 6,
"medium": {
"release": {
"id": "dde6ecee-8e9b-4b46-8c28-0f8d659f83ac",
"title": "Tecno Fes, Volume 2"
},
"position": 1,
"track_count": 11
},
"artists": [{
"id": "57c1e5ea-e08f-413a-bcb1-f4e4b675bead",
"name": "Gigi D\u2019Agostino"
}],
"title": "You Spin Me Round"
}],
"id": "2e0a7bce-9e44-4a63-a789-e8c4d2a12af9"
}, ....
Failed Code (example):
string = '\u0420\u043e\u0441\u0441\u0438\u044f'
print string.encode('utf-8')
I am using this on a windows 7 machine and have python 2.7 and running this code on a command line terminal.. I have the output I get below:
C:\Python27>python junk.py Gigi DGÇÖAgostino Gigi D?Agostino Gigi D\u2019Agostino
I am expecting the output to be Gigi D' Agostino
`print u'Gigi D\u2019Agostino'.encode('utf-8')`'
`print u'Gigi D\u2019Agostino'.encode('iso-8859-15', 'replace')`
`a = u'Gigi D\u2019Agostino' import re a = re.sub(r'[\x80-\xFF]+', lambda x: x.group(0).encode('latin1').decode('utf8'), a) print a.encode('utf8')` – Prem Minister Jan 15 '13 at 19:57