【发布时间】:2021-09-29 14:55:05
【问题描述】:
我有时会遇到这个问题。但总能解决。这下不可能找到解决办法了。同一主题有很多帖子,但在我的情况下没有解决方案。 我正在尝试从我的 api 获取数据。它有时可以工作(使用没有无值的数据)并且使用包含无值的数据,它不起作用。我认为问题在于无值。我有这个错误
Exception Type: JSONDecodeError
Exception Value:
Expecting value: line 1 column 75 (char 74)
感谢任何帮助。
@api_view(['GET'])
def edges_of_a_network(request, pk):
try:
roadnetwork = RoadNetwork.objects.get(pk=pk)
except RoadNetwork.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
else:
edges = Edge.objects.filter(network=roadnetwork)
edges = str(list(edges.values("edge_id", "name",
"length", "speed", "lanes"))).replace("'",'"')
edges = json.loads(edges)
edges = json.dumps(edges, indent=2)
if request.method == 'GET':
return HttpResponse(edges, content_type="application/json")
【问题讨论】:
标签: python json django django-rest-framework jsondecoder