django将qureyset中的数据转换成json格式
import json from django.shortcuts import HttpResponse from django.http import JsonResponse from databases_models import models from django.core import serializers def serverhost_list(request): host_list = models.GameServerVersion.objects.all() host_list_json = serializers.serialize("json",host_list) #获取到的数据类型为字符串(str) host_list_json = json.loads(host_list_json) #将字符串数据转成json类型 print(type(host_list_json)) result = { "status": 0, "message": host_list_json } return HttpResponse(json.dumps(result,ensure_ascii=False),content_type='application/json') #使用HttpResponse的参数返回数据中文不乱码
一些事情一直在干,说不定以后就结果了呢
本文来自博客园,作者:chenjianwen,转载请注明原文链接:https://www.cnblogs.com/chenjw-note/p/13735256.html