I need the "u" prefixed removed because I am passing these json serialized lists over to the front end and handling them with javascript. Javascript can not make sense of these "u"'s.
Here is the code:
context['list_of_dicts'] = serialize('json', my_list_of_dicts)
# this function is wrapped with a @json response decorator
@json_response looks like:
def json_response(func):
"""
A decorator thats takes a view response and turns it
into json. If a callback is added through GET or POST
the response is JSONP.
"""
def decorator(request, *args, **kwargs):
objects = func(request, *args, **kwargs)
if isinstance(objects, HttpResponse):
return objects
try:
data = simplejson.dumps(objects)
if 'callback' in request.REQUEST:
# a jsonp response!
data = '%s(%s);' % (request.REQUEST['callback'], data)
return HttpResponse(data, "text/javascript")
except:
data = simplejson.dumps(str(objects))
return HttpResponse(data, "application/json")
return decorator
On the frontend, I get the error:
Uncaught SyntaxError: Unexpected token u in JSON at position 0
That's because the "u" prefix has not been removed. How do I remove the "u" prefix so my frontend can decode the JSON?