一、几种序列化
import json # 序列化queryset def xuliehuaQueryset(request): querylist = models.LsTable.objects.all() querylist_json = serializers.serialize("json",querylist ) return HttpResponse(querylist_json) # 序列化set def xuliehuaQueryset(request): set = {"status":"true","model":"info"} set_json = json.dumps(querylist) return HttpResponse(set_json) # 序列化含有queryset的set,此时返回的queryset是一个个的字母列表形式 def xuliehuaQueryset(request): querylist = models.LsTable.objects.all() set ={"status":"true","querylist":serializers.serialize("json",querylist)} set_json = json.dumps(set ) return HttpResponse(set_json) # 序列化含有queryset的set,此时返回的queryset才是object列表形式 def xuliehuaQueryset(request): querylist = models.LsTable.objects.all() set ={"status":"true","querylist":json.loads(serializers.serialize("json",querylist))} set_json = json.dumps(set ) return HttpResponse(set_json)
标签:set,queryset,querylist,json,quertset,HttpResponse,序列化 From: https://www.cnblogs.com/songwmeta/p/17950190