0

我正在开发一个必须调用 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];
    strnew=@"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 *urlLoc=@"";
    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];

}
4

1 回答 1

0

您必须使用一些键值来获取所有数据,例如这行代码:

NSString* latestvalue = [[[json objectForKey:@"countries"] objectAtIndex:0] objectForKey:@"countryName"];
于 2013-02-14T05:30:40.467 回答