As a result of an API call I get the following object of <type 'unicode'>
:
{"From":"en","Translations":[{"Count":0,"MatchDegree":100,"MatchedOriginalText":"","Rating":5,"TranslatedText":"Cómo estás"}]}
but when I try to parse it with simplejson_loads()
I get this error:
simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
How can I handle this kind of objects?
EDIT II: the JSON is correct. What messes up things is the BOM at the beginning of the string. Trying to get rid of it with .encode('utf-8-sig')
produces the error
UnicodeEncodeError: 'ascii' codec can't encode character u'\ufeff' in position 2: ordinal not in range(128)
but somewhere in this discussion I found a solution that worked for me:
if u.startswith(u'\ufeff'):
u = u[1:]
And I'm quite tempted to just get away with it and be happy.