2013-02-14 40 views
0

我正在開發一個應用程序,我必須調用PHP Web服務。 我傳遞了所有提到的參數,但仍然響應給沒有空字符串的輸出。如何在PHP Web服務中傳遞參數?

這些是PHP的Web服務的以下參數:

method: POST 
parameters: { 
title fname lname conNo pwd email city state country 
} 

這些都是成功的和不成功的響應的條件:

Respons: 

    case a: On Sucessfull Registration 

{ 
    'userName' : 'fName', 'outhProvider' : 'normal', 'status' : 'success' 'userId' : 'userId', 
    'title' : 'title', 'firstName' : 'fName', 'lastName' : 'lName', 'city' : 'city', 'contactNo' : 'conNo', 'state' : 'state', 
    'country' : 'country' 
    } 


    case b: On Duplicate Registration 
{ 
    「status」 : 「Data already exist」 } 

    case c: On Data not sufficient 
    { 
     「status」 : 「No data supplied」 } 

我已經使用POST方法: -

-(void)RegisterUser 
{ 
    NSString *strnew=[[NSString alloc]init]; 
    [email protected]"buyer"; 

    SBJSON *json = [SBJSON new]; 
    json.humanReadable = YES; 
    responseData = [[NSMutableData data] retain]; 


    NSString *service = @"http://www.ajatus.in/ajatus_templates/Templaton/wp-content/plugins/realestate/registrationJson.php"; 



    NSString *requestString = [NSString stringWithFormat:@"{\"title\":\"%@\",\"fName\":\"%@\",\"lName\":\"%@\",\"conNo\":\"%@\",\"pwd\":\"%@\",\"email\":\"%@\",\"city\":\"%@\",\"state\":\"%@\",\"country\":\"%@\"}",titlename.text,fname.text,lname.text,contactno.text,password.text,email.text,city.text,state.text,country.text]; 

    NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]]; 

    NSString *[email protected]""; 
    urlLoc = [urlLoc stringByAppendingString:service]; 

    NSLog(@"URL:- %@",urlLoc); 


    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: 
            [NSURL URLWithString: urlLoc]]; 
     NSString *postLength = [NSString stringWithFormat:@"%d", [requestData length]]; 
    [request setHTTPMethod: @"POST"]; 
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 
    [request setHTTPBody: requestData]; 

    self.connection = [NSURLConnection connectionWithRequest:request delegate:self]; 

} 

回答

0

您必須使用一些關鍵值來獲取像下面這行代碼的所有數據:

NSString* latestvalue = [[[json objectForKey:@"countries"] objectAtIndex:0] objectForKey:@"countryName"]; 
相關問題