2
我正在制作一个iPhone应用程序,它需要我使用网站表单来获取数据库中的值,并且可以通过我的iPhone应用程序以JSON格式进行查询。在iphone应用程序中的表格
现在我想,因为我的网站形式只有5-6个字段填满,我可以在我的iphone应用程序本身做一个表单吗?然后,我可以将这些表单数据以JSON格式发送到网络服务器。 有人请指导我。
我正在制作一个iPhone应用程序,它需要我使用网站表单来获取数据库中的值,并且可以通过我的iPhone应用程序以JSON格式进行查询。在iphone应用程序中的表格
现在我想,因为我的网站形式只有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
这些链接可以帮助你