输出Json字符串?

时间:2012-07-10 03:38:52

标签: json httpresponse

我只想创建以下Json输出作为HttpResponse:

{ "status": "OK", "verified": true }

但出于某种原因不断出现错误。

1 个答案:

答案 0 :(得分:-1)

想出来。我这样做了:

results= [{"status": "INVALID_REQUEST", "verified": False}]         
return HttpResponse(simplejson.dumps(results), mimetype='application/json')

为什么这也会起作用?

results= [{"status": "INVALID_REQUEST", "verified": False}]
output = serializers.serialize('json', results, indent=2)
return HttpResponse(output, mimetype='application/json')