I am trying to parse json object in my Django view which has been passed through from client by ajax via post method.
JS:
$.post ('/update_vendor_merchandise_types/', JSON.stringify(json_obj));
View:
def update_vendor_merchandise_types(request):
print json_object
# The output gives me
# QueryDict: <QueryDict: {u'[{"merchandise_id":"3"},{"merchandise_id":"4"}]': [u'']}>
json_object = json.load(request.POST) # Error arises
pass
On the commented line 'QueryDict' object has no attribute 'read' error arises.
What am I doing wrong ?
Eventually, my goal is to get access to merchandise_id values. I try
d = request.POST.iteritems()
for key, value in d:
print value
and expect something like
3
4
json.loadto convert json format to a dict. Here, you have a dict you want to convert tojson. You would be doingjson.dumps(request.POST.copy())request.POSTis a dictionary which should contain any data you actually need, there isn't any point jsonifying it