如何从nsobject类获取api响应字符串值到iOS中的视图控制器

时间:2014-02-21 11:00:39

标签: .net json ios6

   -(void) NSURLConnectionFunction:(NSString *)feedURLString:(NSString *)methodName{
@try{
    // AppDelegate *appDelegate =(AppDelegate *)[[UIApplication sharedApplication] delegate];
    //NSLog(@"Call");
    NSString *strurl=[NSString stringWithFormat:@"%@%@",APIURL,methodName];
    NSURL *url1=[NSURL URLWithString:strurl];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url1
                                                           cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                       timeoutInterval:0.0];

    NSData *requestData = [NSData dataWithBytes:[feedURLString UTF8String] length:[feedURLString length]];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-length"];
    [request setHTTPBody:[feedURLString dataUsingEncoding:NSUTF8StringEncoding]];
    [request setHTTPBody: requestData];
    [request setHTTPShouldHandleCookies:YES];
    conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
    NSLog(@"Exception %@", request);
    if (conn) {
        receivedData=[[NSMutableData alloc]init];

    } else {
        UIAlertView * alert_error = [[UIAlertView alloc] initWithTitle:@"Unable to connect to remote server, please check your network settings and try again" message:@"" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
        [alert_error show];
    }
}

@catch (NSException *e) {
    NSLog(@"Exception %@", e);
}

}

我想从api_call nsobject类获取响应字符串到我的视图控制器。我是iPhone应用程序的新手,请任何人帮助我。 `

  

块引用

0 个答案:

没有答案