1đź‘Ť
Request objects GET and POST can contain multiple values of same key. As some HTML form elements, notably , pass multiple values for the same key.
You are passing the request.POST object to JSON serializer which doesn’t allow multiple keys with same name. So please inspect your request.POST data and see if you are getting multiple keys with same name or not. If yes then you have to process this data before passing to JSON load function.
I hope it will give you some pointers to solve the problem
1đź‘Ť
This is what I finally found out… the problem started in objective c, passing the dictionary as is to AFNetworking caused the funny looking keys on the server side so
- I’ve converted the NSDictionary to NSData
- Converted the NSData to NSString
- created a new dictionary with a “root” dummy key and the converted string as value
Here is my updated working code:
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setObject:[self getProductDictionary] forKey:@"prodDic"];
[parameters setObject:ApplicationDelegate.userUniqueId forKey:@"userID"];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parameters options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
[manager POST:BaseURLString parameters:[[NSDictionary alloc] initWithObjectsAndKeys:jsonString, @"root",nil] success:^(AFHTTPRequestOperation *operation, id responseObject) {...}
then in the server side:
import json
def foo(request):
if request.method == 'POST':
request_data=json.loads(request.POST['root'])
products=request_data['prodDic']
for key in products:
value=products[key]
#do my stuff
return HttpResponse("Done")
hope this save someone time & agony 🙂
- [Answered ]-Emailing to new top-level domains (TLDs) in django
- [Answered ]-How to create a token using jquery with django passing variable to the front?
- [Answered ]-Objects to support the front page of my Django powered web site?
- [Answered ]-Django form save can't be used update a model instance?