ios - How to parse web service data into NSString? -
i facing problem in parsing data web service response. call web service , response nslog
, need capture data nsstring
.
here sample code:
-(void)connection:(nsurlconnection *) connection didreceiveresponse: (nsurlresponse *) response { } -(void)connection:(nsurlconnection *) connection didreceivedata:(nsdata *) data { nsstring *strdata; strdata = [[nsstring alloc]initwithdata:data encoding:nsutf8stringencoding]; nsxmlparser *xmlparser = [[nsxmlparser alloc] initwithdata:data]; [xmlparser setdelegate:self]; [xmlparser parse]; soapresultsstring=[[nsmutablestring alloc]init]; recordresults =yes; } nsstring *xmlparserstring; nsmutablestring *soapresultsstring; bool recordresults; -(void)parserdidenddocument:(nsxmlparser *)parser { } -(void)parser:(nsxmlparser *)parser didstartelement:(nsstring *)elementname namespaceuri:(nsstring *) namespaceuri qualifiedname:(nsstring *)qname attributes: (nsdictionary *)attributedict { xmlparserstring=elementname; if( [xmlparserstring isequaltostring:@"ns:return"]) { recordresults =yes; soapresultsstring = [[nsmutablestring alloc] init]; } } -(void)parser:(nsxmlparser *)parser foundcharacters:(nsstring *)string { if( recordresults ) { [soapresultsstring appendstring: string]; nslog(@"inside%@",string); } } -(void)parser:(nsxmlparser *)parser didendelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname { if( [elementname isequaltostring:@"ns:return"]) { nslog(@"parser==>%@",parser); nslog(@"namespaceurl==>%@",namespaceuri); nslog(@"qname==>%@",qname); nsdata *data = [soapresultsstring datausingencoding:nsutf8stringencoding]; nsdictionary *json = [nsjsonserialization jsonobjectwithdata:data options:0 error:nil]; // nslog(@"json==>%@",json); nsarray *planarray = [json objectforkey:@"hello_history"]; nslog(@"planarraycount==>%lu",(unsigned long)[planarray count]); nsmutablearray *datasource = [nsmutablearray arraywithcapacity:planarray.count]; (int = 0 ; i<[planarray count]; i++) { recordresults = no; txn_id=[[[json valueforkey:@"hello_history"]valueforkey:@"date"]objectatindex:i]; loginid = [[[json valueforkey:@"hello_history"]valueforkey:@"time"]objectatindex:i]; } } }
the problem getting outputupto method
-(void)parser:(nsxmlparser *)parser foundcharacters:(nsstring *)string
but parsing method not @ called
-(void)parser:(nsxmlparser *)parser didendelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname
is there alternate way capture string
Comments
Post a Comment