我通过 Python/Django 将数据作为 JSON 返回。
我使用了以下代码:
jsonObject = serializers.serialize('json', object, fields=('value', 'record_time'))
return HttpResponse(json.dumps(jsonObject), mimetype="application/json")
问题是我得到如下响应:
"[{\"pk\": null, \"model\": \"model.table\", \"fields\": {\"record_time\": \"2009-11-18T22:45:44Z\", \"value\": 0.6533125480476399}}, {\"pk\": null, \"model\": \"model.table\", \"fields\": {\"record_time\": \"2009-11-19T15:02:15Z\", \"value\": 0.4386133754377899}}]"
我应该以以下格式获取它:
"[
{
"pk": null,
"model": "model.table",
"fields":
{
"record_time": "2009-11-18T22:45:44Z",
"value": 0.6533125480476399
}
},
{
"pk": null,
"model": "model.table",
"fields":
{
"record_time": "2009-11-19T15:02:15Z",
"value": 0.4386133754377899
}
}
]"
我在哪里错了?