36👍
✅
You are trying to use the wrong method. json.loads
is for loading JSON to Python. If you want to convert Python to JSON, you need json.dumps
.
result = json.dumps(response[1])
5👍
That dict is in Python dict literal format, not JSON. You can do:
import ast
result = ast.literal_eval(response[1])
to read in the response in that format. Are you sure that Django hasn’t already JSON-decoded the response?
- [Django]-Pass request context to serializer from Viewset in Django Rest Framework
- [Django]-What's the difference between staff, admin, superuser in django?
- [Django]-Django – show the length of a queryset in a template
3👍
i have use json on django , i use this :
import simplejson as json
#to encode
final= {'first':first_data,'second':second_data}
json.dumps(final)
#to decode this is the example from python's api
json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
- [Django]-Import error django corsheaders
- [Django]-Simply save file to folder in Django
- [Django]-Django Forms: pass parameter to form
Source:stackexchange.com