【发布时间】:2012-07-11 14:32:53
【问题描述】:
我想通过POST 方法使用JSON 数据类型将在iOS 上创建的新对象发送到接收服务器。据我所知,在 iOS 中从服务器接收数据,所有JSON 处理都被 Apple 简化了,引入了 iOS 5。但与 GETting JSON 对象不同,POST 那些不是t真的描述了我能找到的任何地方......
我尝试解决问题的第一步如下所示:
//build an info object and convert to json
NSDictionary *newDatasetInfo = [NSDictionary dictionaryWithObjectsAndKeys:name, @"name", language, @"language", nil];
//convert object to data
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:newDatasetInfo options:kNilOptions error:&error];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:someURLSetBefore];
[request setHTTPMethod:@"POST"];
// any other things to set in request? or working this way?
[[NSURLConnection alloc] initWithRequest:request delegate:self];
// What to do with NSURLConnection? Or how to send differently?
但我真的不知道如何使用 POST 方法将 JSON 对象发送到服务器。 有人可以帮帮我吗?
【问题讨论】:
标签: json http post ios5 webserver