首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iphone应用程序中的表单

iphone应用程序中的表单
EN

Stack Overflow用户
提问于 2012-03-01 09:47:06
回答 1查看 298关注 0票数 2

我正在制作一个iphone应用程序,它需要我使用网站表单将值放入数据库中,我可以通过我的iphone应用程序以JSON形式进行查询。

现在我在想,既然我的网站表单只有5-6个字段需要填写,我可以在我的iphone应用程序中创建一个表单吗?然后,我可以将表单数据以JSON格式发送到the服务器。有谁能给我指点一下。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-01 13:03:16

您可以通过post方法将数据发送给jason。

代码语言:javascript
复制
-(void)registration:(NSString *)nickName 
  TeamName:(NSString *)teamName
  Age:(NSString *)age
  Nationality:(NSString *)countryName

{   
NSString *JSON = [NSString stringWithFormat:@"{\"NICKNAME\":\"%@\"",nickName];
JSON = [JSON stringByAppendingFormat:@",\"TEAM_NAME\":\"%@\"",teamName];
JSON = [JSON stringByAppendingFormat:@",\"AGE\":\"%@\"",age];
JSON = [JSON stringByAppendingFormat:@",\"NATIONALITY\":\"%@\"",countryName];
NSLog(@"%@", JSON);

  NSData *postData = [JSON dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];    
  NSString *strURL = [NSString stringWithFormat:@"%@%@", kServerPath, kUserRegisterPath];

NSLog(@"Resgistration URL: %@", strURL);

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:strURL] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:120.0];    

[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];

[request setHTTPBody:postData];

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:[WebServices sharedInstance]];


if(theConnection) {
    NSLog(@"connection made");
}

else {
    NSLog(@"theConnection is NULL");

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error " message:@"Network not responding"  delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}

}

http://iosdevelopertips.com/networking/iphone-json-flickr-tutorial-part-1.html

iPhone/iOS JSON parsing tutorial

这些链接可能对您有所帮助

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9509505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档