Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iphone Http request response using json

Tags:

I am trying to send the data to server and get the response. Data is reaching server but I am not getting any response. The value of response data is nil bcd of which it's throwing an exception,

-JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=11 \"Unexpected end of string\" UserInfo=0x4e2dd70 {NSLocalizedDescription=Unexpected end of string}"

Can anyone pls help me....

My code:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.0.83:8082/WebServiceProject/AcessWebservice?operation=login"]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];

NSURLResponse *theResponse =[[NSURLResponse alloc]init];
NSError *theError = NULL;
NSArray *keys = [NSArray arrayWithObjects:@"UserId", @"Password", nil];
NSArray *objects = [NSArray arrayWithObjects:@"rajin.sasi", @"abhi1551", nil];
NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];


NSString* jsonString = [jsonDictionary JSONRepresentation];

SBJSON *jsonParser = [SBJSON new];
[jsonParser objectWithString:jsonString];

NSLog(@"Val of json parse obj is %@",jsonString);   
[request setHTTPMethod:@"POST"];

[request setValue:jsonString forHTTPHeaderField:@"json"];
responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&theError];      
[request setHTTPBody:responseData];

NSMutableString* stringData= [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
NSDictionary    *jsonDictionaryResponse = [stringData JSONValue];

NSString *json_message=[jsonDictionaryResponse objectForKey:@"message"];

printf("Json string is %s **********",[json_message UTF8String]);