2012-03-01 3 views
2

Я делаю приложение iphone, которое требует, чтобы я использовал форму веб-сайта для получения значений в базе данных и который я могу запросить через свое приложение iphone в форме JSON.Форма в приложении iphone

Теперь я думаю, что, так как моя форма сайта имеет только 5-6 полей, чтобы заполнить, могу ли я сделать форму в моем приложении iphone? Затем я могу отправить эти данные формы в формате JSON на веб-сервер. Кто-нибудь, пожалуйста, назовите меня.

ответ

1

Вы можете отправить данные в jason методом post.

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

эти ссылки могут помочь вам

Смежные вопросы