如何在 JSON 字符串中包含注释?
我有一个视图返回编码为 JSON 的货运列表...
def get_new_shipments(request):
# ...
shipments = Shipment.objects.filter(filter).exclude(**exclude).order_by(order) \
.annotate(num_bids=Count('bids'), min_bid=Min('bids__amount'), max_bid=Max('bids__amount'))
return json_response(shipments)
def json_response(data):
response = HttpResponse(mimetype='application/json')
serializer = serializers.get_serializer("json")()
data = list(data)
serializer.serialize(data, ensure_ascii=False, stream=response)
return response
但我在 JSON 中的任何地方都没有看到这些注释...我如何才能将它们包含在内?
I've got a view that returns a list of shipments encoded as JSON...
def get_new_shipments(request):
# ...
shipments = Shipment.objects.filter(filter).exclude(**exclude).order_by(order) \
.annotate(num_bids=Count('bids'), min_bid=Min('bids__amount'), max_bid=Max('bids__amount'))
return json_response(shipments)
def json_response(data):
response = HttpResponse(mimetype='application/json')
serializer = serializers.get_serializer("json")()
data = list(data)
serializer.serialize(data, ensure_ascii=False, stream=response)
return response
But I don't see those annotations in the JSON anywhere... how do I get them to be included?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎有效:
信用
This seems to work:
credit