ios - My app is not parsing the JSON response -
i new ios , in project using nsurlconnection
integrating services when send request server got empty response , error:
jsonvalue failed. error trace is: ( "error domain=org.brautaset.json.errordomain code=11 \"unexpected end of string\" userinfo={nslocalizeddescription=unexpected end of string}" )
but when check in post man client response coming server
but why response not coming in app please me one.
my dicitionary request:-
dictionary { medicaidid = 101229518299; coriders = ( 2870862 ); escort = { name = ""; relation = 2; }; schurgentcare = 0; test = tripcomments; transportmode = regular; tripdate = "10/02/2016 - 09:32 pm"; triplegs = ( { appttime = "10/02/2016 - 09:32 pm"; territoryid = 3; triplegtype = 4; destination = { address1 = "335 vandalia st"; address2 = ""; city = lapaz; phoneno = 5747842191; providerid = 0; state = in; zip = 46537; }; source = { address1 = "335 vandalia st"; address2 = ""; city = lapaz; phoneno = 5747842191; providerid = 1; state = in; zip = 46537; }; } ); tripnotes = { hascarseat = 0; hassplequipment = 0; needliftvan = 0; transferwheelchair = 0; wheelchaircanfold = 1; wheelchaircannotfold = 1; }; urgentcare = 0; }
my code:-
-(void)servicecalling :(nsdictionary*)mydictionary{ nserror *error = nil; nsdata *jsondata = [nsjsonserialization datawithjsonobject:mydictionary options:kniloptions error:&error]; nsstring *urlstr = [nsstring stringwithformat:@"%@trip/create",kserverbaseurl]; nslog(@"urlstr --->> %@",urlstr); nsurl *serviceurl=[nsurl urlwithstring:urlstr]; nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:serviceurl]; [request settimeoutinterval:120]; [request sethttpmethod:@"post"]; [request setvalue:@"application/json" forhttpheaderfield:@"accept"]; [request setvalue:@"application/json" forhttpheaderfield:@"content-type"]; [request setvalue:accesstoken forhttpheaderfield:@"authorization"]; [request setvalue:@"json" forhttpheaderfield:@"data-type"]; [request sethttpbody:jsondata]; nsurlconnection *connectionmanager = [[nsurlconnection alloc] initwithrequest:request delegate:self]; if (connectionmanager) { nslog(@"connected"); } else{ nslog(@"not connected"); } } -(void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data{ [downloadedmutabledata appenddata:data]; } - (void)connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error{ [mbprogresshud hidehudforview:self.view animated:yes]; if (error.code == nsurlerrortimedout){ nslog(@"request time out"); } else{ nslog(@"response --->> errorrrrrr"); } } // method call,when server response success - (void)connectiondidfinishloading:(nsurlconnection *)connection{ [mbprogresshud hidehudforview:self.view animated:yes]; nsdictionary *responedict = [[[nsstring alloc]initwithdata:downloadedmutabledata encoding:nsutf8stringencoding] jsonvalue]; nslog(@"response --->> %@",responedict); }
Comments
Post a Comment