2012-03-01 3 views
2

나는 데이터베이스에 값을 얻기 위해 웹 사이트 양식을 사용하고 JSON 양식으로 내 아이폰 앱을 통해 쿼리 할 수있는 아이폰 앱을 만들고 있습니다.아이폰 앱의 양식

이제 웹 사이트 양식이 채우기 위해 5-6 개의 입력란 만 갖고 있기 때문에 iPhone 앱 자체에서 양식을 만들 수 있습니까? 그런 다음 양식 데이터를 JSON 형식으로 웹 서버에 보낼 수 있습니다. 누군가 나를 안내 해주십시오.

답변

1

제이슨에게 우편 방법으로 데이터를 보낼 수 있습니다.

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

이 링크는 당신에게

도움이 될 수 있습니다
관련 문제