gpt4 book ai didi

iphone - iphone 应用程序中的表单

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:53:10 25 4
gpt4 key购买 nike

我正在制作一个 iPhone 应用程序,它要求我使用网站表单将值输入数据库,并且我可以通过我的 iPhone 应用程序以 JSON 形式查询。

现在我在想,由于我的网站表单只有 5-6 个字段需要填写,我可以在我的 iPhone 应用程序中自己制作一个表单吗?然后我可以将该表单数据以 JSON 格式发送到网络服务器。有人请指导我。

最佳答案

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

-(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

这些链接可能对你有帮助

关于iphone - iphone 应用程序中的表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9509505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com