Hey, I need to make a HTTP POST request with an array of NSDictionary objects.
When I do this, however, I notice on the server side that the NSDictionary object does not get deserialized to a hash. It gets deserialized to a string - which is not what i want.
This is how I send the parameter from the client (IPhone) side:
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 (rails) side:
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 this is a common problem that people face. So there definitely is a solution for this.
Thanks in advance for all the comments/answers.