如何在iOS5中将JSON数据对象发布到服务器?

如何在iOS5中将JSON数据对象发布到服务器?,第1张

概述我想使用 JSON数据类型使用POST方法将在iOS上创建的新对象发送到接收服务器.根据我对从iOS服务器接收数据的了解,苹果公司通过引入iOS 5简化了所有JSON处理.但与GETting JSON对象相比,POST这些并不是我能找到的任何地方. . 我尝试解决问题的第一步看起来如下: //build an info object and convert to json NSDictio 我想使用 JSON数据类型使用POST方法将在iOS上创建的新对象发送到接收服务器.根据我对从iOS服务器接收数据的了解,苹果公司通过引入iOS 5简化了所有JsON处理.但与GETting JsON对象相比,POST这些并不是我能找到的任何地方. .

我尝试解决问题的第一步看起来如下:

//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对象发送到服务器.
有人可以帮帮我吗?

解决方法 我通过尝试一下来解决这个问题,这是我的代码:
//build an info object and convert to Json    NSDictionary *newDatasetInfo = [NSDictionary dictionaryWithObjectsAndKeys:name,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"];    [request setValue:@"application/Json" forhttpheaderFIEld:@"Content-Type"];    [request setValue:@"application/Json" forhttpheaderFIEld:@"Accept"];    [request sethttpBody:JsonData];    // print Json:    NSLog(@"JsON summary: %@",[[Nsstring alloc] initWithData:JsonData                                                     enCoding:NSUTF8StringEnCoding]);    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];    [connection start];
总结

以上是内存溢出为你收集整理的如何在iOS5中将JSON数据对象发布到服务器?全部内容,希望文章能够帮你解决如何在iOS5中将JSON数据对象发布到服务器?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1101904.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存