Well the problem is that that string is not valid JSON syntax. It is valid Python syntax, but not JSON, for two reasons:
- JSON doesn't allow single-quote strings,
'38'
, only double-quote, "38"
.
- JSON doesn't allow a u before the string,
u"38"
, only bare strings which are implicitly Unicode, "38"
.
You need to either change the input format, or use something which can process Python strings instead.
You could use eval
, which reads strings containing Python syntax, but note that this is highly dangerous if you are accepting arbitrary input, since someone can supply code to execute. Nevertheless, it works:
>>> eval(u"[u'38', u'36', u'34', u'32']")
[u'38', u'36', u'34', u'32']
Edit: khachik's answer is probably better than eval
, since it won't be susceptible to evaluating arbitrary Python code, only reading Python data structures.