iphone - how to get server response and if server response is "Success" after show alert by JSON using objective c -


nsstring *data = [nsstring stringwithformat:@"username=%@&password=%@",usertxt.text,pwdtxt.text,[nsnumber numberwithbool:yes]];     nsdata *postdata = [data datausingencoding:nsasciistringencoding allowlossyconversion:yes];     nsstring *postlength = [nsstring stringwithformat:@"%d", [postdata length]]; 

// preaparing url request send data.

nsmutableurlrequest *request = [[nsmutableurlrequest alloc] init] ; connection=[[nsurlconnection alloc] initwithrequest:request delegate:self]; nsstring *url = [nsstring stringwithformat:url_path]; [request seturl:[nsurl urlwithstring:url]]; [request sethttpmethod:@"post"]; [request setvalue:postlength forhttpheaderfield:@"accept"]; [request sethttpbody:postdata]; [request settimeoutinterval:7.0];  nsurlresponse *_response; nserror *error; nsdata *urldata = [nsurlconnection sendsynchronousrequest:request returningresponse:&_response error:&error]; nsstring *str=[[nsstring alloc]initwithdata:urldata encoding:nsutf8stringencoding]; 

//print server response

nslog(@"login response:%@",str); 

//parse json string nsdictionary

 nsdictionary* json = [nsjsonserialization jsonobjectwithdata:urldata                                                      options:kniloptions                                                       error:&error];  

try this
don't need use json try code response server

nsstring *string= [[nsstring alloc]initwithformat:@"url"];         nslog(@"%@",string);         nsurl *url = [nsurl urlwithstring:string];         nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url];         [request sethttpmethod:@"post"];          nsurlresponse *response;         nserror *err;         nsdata *responsedata = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&err];         nslog(@"responsedata: %@", responsedata);         nsstring *str = [[nsstring alloc] initwithdata:responsedata encoding:nsutf8stringencoding];         nslog(@"responsedata: %@", str);         nsstring *str1 = @"1";         if ([str isequaltostring:str1 ])         {              uialertview *alert = [[uialertview alloc]initwithtitle:@"successfully" message:@"" delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil, nil];             [alert show];         }         else         {             uialertview *alert = [[uialertview alloc]initwithtitle:@"try again" message:@"" delegate:self cancelbuttontitle:@"try later" otherbuttontitles:@"call", nil];             alert.tag = 1;             [alert show];         } 

if response string success put in place of @"1"


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -