Assuming that I have function get_a_color in a Django views.py:
from django.utils import simplejson
def get_a_color(request):
colors = ['red', 'blue', 'yellow']
data = simplejson.dumps(colors)
return HttpResponse(data, mimetype='application/javascript')
How will I extract the color ‘red’ for example using the jQuery $.getJSON function?
Not sure exactly what you’re looking to do, but I put a quick fiddle together to show how to get red out of your returned JSON array….