嘿,我需要使用一组 NSDictionary 对象发出 HTTP POST 请求。
但是,当我这样做时,我在服务器端注意到 NSDictionary 对象没有反序列化为哈希。它被反序列化为一个字符串——这不是我想要的。
这就是我从客户端(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];
这是在服务器(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)
我相信这是人们面临的普遍问题。所以肯定有一个解决方案。
提前感谢所有评论/答案。