Why does Django give me this exception
[(7, u'Acura'), (18, u'Alfa Romeo'), ...] is not JSON serializable
When I try
data = VehicleMake.objects.filter(model__start_year__gte=request.GET.get('year',0)).values_list('id','name')
return HttpResponse(simplejson.dumps(data, ensure_ascii=False), mimetype='application/json')
?
It's just a simple list of tuples. It works with my other hard-coded list that's in almost exactly the same format. Is it because the strings are unicode? How do I handle that?
It works fine when I encode it as a dict:
def get_makes(request):
year = request.GET.get('year',0)
data = VehicleMake.objects.filter(model__start_year__lte=year, model__stop_year__gte=year).order_by('name').distinct().values_list('id','name')
return HttpResponse(simplejson.dumps(odict(data), ensure_ascii=False), mimetype='application/json')
Some makes have accented characters... could that be it? Yes, the list is big (~900 makes total).