2012-03-01 12 views
2

私はデータベースに値を取得するためにウェブサイトのフォームを利用する必要があるiphoneアプリを作成しています。これはJSONフォームで自分のiPhoneアプリを使ってクエリできます。iphoneアプリのフォーム

私のウェブサイトのフォームは5〜6個のフィールドしかないので、私は自分のiPhoneアプリケーション自体にフォームを作成できますか? JSON形式のフォームデータをWebサーバーに送信できます。 誰かが私を導いてください。

答えて

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

これらのリンクは、あなた

役立つかもしれません