Hey, I need to make an HTTP POST request with an array of NSDictionary objects.
However, when I do this, on the server side, I notice that the NSDictionary object is not being deserialized to hash. It deserializes to a string - this is not what I want.
This is how I send the parameter from the client side (IPhone):
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; for (ABContact *c in contactsWithEmailsOrPhones){ NSString *phoneNumber = [[ABContactsHelper class] contactPhoneNumber:c]; NSString *email = [[c emailArray] objectAtIndex:0]; NSLog(@"looping: %@, %@", phoneNumber, email); NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: phoneNumber, @"phone", email, @"email", [c firstname], @"firstname", [c lastname], @"lastname", nil]; [request addPostValue:dict forKey:@"contacts[]"]; } [request setDelegate:self]; [request startAsynchronous];
This is how it looks when it is deserialized on the server side (rails):
Started POST "/app/find_friends" for 67.164.97.48 at Thu Sep 23 14:40:37 -0700 2010 Processing by app#find_friends as HTML Parameters: {"contacts"=>["{\n email = \"xx\";\n firstname = xx;\n lastname = xx;\n phone = \"xx\";\n}", "{\n email = \"xx\";\n firstname = xx;\n lastname = xx;\n phone = \"xx\";\n}"]} Completed 200 OK in 0ms (Views: 0.3ms | ActiveRecord: 0.0ms)
I am sure that this is a common problem that people face. So there is definitely a solution for this.
Thanks for all the comments and answers.
amehta
source share