我在代码行下调用它的工作正常
return HttpResponse( json.dumps(rows), content_type='application/json')
获得如下输出:
["f8823b39f5", "000002de", "176", "STAT", "NY"]
我想要JSON格式,因为我运行下面的代码:
return HttpResponse( json.dumps(dict(rows)), content_type='application/json')
得到以下错误:
'dict' object is not callable
Excepting output like below:
{"earning1": "f8823b39f5", "earning2": "000002de", ...}
请帮我。如何解决这个问题呢。
使用django序列化程序将django对象转换为其他格式
return HttpResponse(serializers.serialize("json", rows))
在这里阅读更多:https://docs.djangoproject.com/en/1.10/topics/serialization/
试试这个。
jsonToPython = json.loads(jsonData)print(jsonToPython)
import json
import requests
headersGet = {'Content-Type': 'application/json; charset=UTF-8', 'Accept': 'application/json'}
p = requests.get("URL",headers=headersGet)
json_data = p.json()
print(json_data)