2013-02-14 41 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"]; 
相关问题