Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.responseData = [NSMutableData data];
    //NSURLRequest *request = [NSURLRequest requestWithURL:
                            //// [NSURL URLWithString:@"https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=//false&key=AIzaSyAbgGH36jnyow0MbJNP4g6INkMXqgKFfHk"]];
    //NSURLRequest *request = [NSURLRequest requestWithURL:
    //[NSURL URLWithString:@"http://162.242.142.88/CarShareService/CarShareService.svc/Login?UserName=alex@rentcentric.com&Password=12345"]];
    NSString * key = [NSString stringWithFormat:@"UserName=%@&Password=",@"alex@rentcentric.com" ,@"12345" ];
    NSURL * url = [NSURL URLWithString:@"http://162.242.142.88/CarShareService/CarShareService.svc/Login"];
    NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"GET"];
    [request setHTTPBody:[key dataUsingEncoding:NSUTF8StringEncoding]];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    NSLog(@"didReceiveResponse");
    [self.responseData setLength:0];

}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [self.responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    NSLog(@"didFailWithError");

    NSLog([NSString stringWithFormat:@"Connection failed: %@", [error description]]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSLog(@"connectionDidFinishLoading");
    NSLog(@"Succeeded! Received %d bytes of data",[self.responseData length]);
    // convert to JSON

    NSError *myError = nil;







    NSDictionary *res = [NSJSONSerialization JSONObjectWithData:self.responseData options:NSJSONReadingMutableLeaves error:&myError];

    //[self setResponseSerializer:responseData];
    NSDictionary *posts = [res objectForKey:@"StatusInfo.StatusCode"];
    if(res == nil){
        NSLog(@"JSON Error: %@", myError);
        return;
    }else{

         NSLog(@"JSON Error%@",myError);
    }








the error is
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x8d6ca50 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900