ios - Error when setting values from JSON on my UITableViewCell -


i have problem when set values on uitableviewcell. data web service in json format, created class contains data json.

that class.

refunds.h

#import <foundation/foundation.h>   @interface refunds : nsobject   -(id)initwithjsondata:(nsdictionary*)data;   @property (assign) nsnumber *refunds_id;  @property (assign) nsnumber *request_number;  @property (strong) nsstring *policy_code;  @property (strong) nsstring *company;   @end 

refunds.m

#import "refunds.h"   @implementation refunds    @synthesize refunds_id;  @synthesize request_number;  @synthesize policy_code;  @synthesize company;  -(id)initwithjsondata:(nsarray*)data{  self = [super init];  if(self){     nslog(@"initwithjsondata method called ");      //nsstring *u = [data valueforkey:@"policy_code"];     //nslog(@"%@",u);      refunds_id =  [data valueforkey:@"id"];     request_number = [data valueforkey:@"request_number"];     policy_code = [data valueforkey:@"policy_code"];     company = [data valueforkey:@"company"];     }     return self;     }     @end 

in viewcontroller use uitableview have implementation

nsmutablearray refunds_view = [[nsmutablearray alloc] init];  (nsdictionary *each_refunds in self.list) {     refunds *refunds = [[refunds alloc] initwithjsondata:each_refunds];     [refunds_view addobject:refunds]; } 

in method

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{} 

i have this:

refunds *current = [refunds_view objectatindex:indexpath.row]; cell.date_admission.text = [current company];  

in line cell.date_admission.text = [current company]; gives me following error

-[__nsarrayi length]: unrecognized selector sent instance 0x8bc4eb0 *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nsarrayi length]: unrecognized selector sent instance 0x8bc4eb0' 

that json format.

[ {     "id": 1,     "holder_rut": 12345678,     "holder_name": "otro pedro",     "rut": 12345678,     "name": "otro pedro",     "refunds_view": [         {             "id": 60,             "request_number": 456789,             "policy_code": "3500009001",             "company": "benefits",             "beneficiary_id": 1,             "concept": "prueba more",             "date": "2014-05-21",             "amount": 20000,             "deductible_amount": 0,             "max_applied": 0,             "yearly_balance": 97,             "payment_amount": 14000,             "payment_method": "deposito",             "bank": "estado",             "account_number": "1234567",             "payment_date": "2014-06-20",             "created_at": "2014-06-18 21:55:41"         }     ] } 

the data need show refunds_view

view controller code

//uitableview methods implemented - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{  static nsstring *simpletableidentifier = @"simplecell";  rowcell *cell = (rowcell *)[tableview dequeuereusablecellwithidentifier:simpletableidentifier];  if (cell == nil) {      //inicilitacion cell custom     cell = [[rowcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:simpletableidentifier]; }   refunds *current = [refunds_view objectatindex:indexpath.row]; nslog(@"company %@",[current company]); cell.date_admission.text = [current company];   return cell; } 

viewdidload

 - (void)viewdidload { [super viewdidload]; // additional setup after loading view nib.  //geting data json refunds sbjsonwriter *jsonwriter = [[sbjsonwriter alloc] init]; nsdictionary *dict = [nsdictionary                       dictionarywithobjects:[nsarray arraywithobjects:rut_user, nil]                       forkeys:[nsarray arraywithobjects:@"rut", nil]]; nsdata *jsondata = [jsonwriter datawithobject:dict];  //url nsurl *url = [nsurl urlwithstring:@"url"];   nsmutableurlrequest *request = [[nsmutableurlrequest alloc] initwithurl:url]; //[request seturl:url]; [request sethttpmethod:@"post"]; [request setvalue:@"application/json" forhttpheaderfield:@"content-type"]; [request setvalue:token forhttpheaderfield:@"x-auth-token"];//token [request setvalue:[nsstring stringwithformat:@"%d", [jsondata length]] forhttpheaderfield:@"content-length"]; [request sethttpbody: jsondata];  nserror *error = [[nserror alloc] init]; nshttpurlresponse *response = nil; nsdata *urldata=[nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error];  nslog(@"response code: %d", [response statuscode]); nsstring *responsedata = [[nsstring alloc]initwithdata:urldata encoding:nsutf8stringencoding];  sbjsonparser *jsonparser = [sbjsonparser new]; nsdictionary *jsonresponse = (nsdictionary *) [jsonparser objectwithstring:responsedata error:nil];//i'm json refunds   self.list = [jsonresponse valueforkey:@"refunds_view"]; nslog(@"quantity of refunds founds %i",[self.list count]);  refunds_view = [[nsmutablearray alloc] init];   (nsdictionary *each_refunds in self.list) {     //nslog(@"each_refound %@",each_refunds);     refunds *refunds = [[refunds alloc] initwithjsondata:each_refunds];     [refunds_view addobject:refunds]; }    } 

i need fix asap. thanks. best regards.

hi everyone. try this

nslog(@"%@",[current company]);  2014-06-26 10:32:13.917 benefits[7178:70b] ( benefits )  cell.sol_number.text = [nsstring stringwithformat:@"%@", current.company]; 

no occurs error value doesn't show complete, show (

any idea this. thanks.

 rewrite refund.m below      #import "refunds.h"       @implementation refunds        @synthesize refunds_id;      @synthesize request_number;      @synthesize policy_code;      @synthesize company;  -(id)initwithjsondata:(nsdictionary*)data {      self = [super init];      if(self)     {         nslog(@"initwithjsondata method called ");          refunds_id =  data[@"id"];         request_number = data[@"request_number"];         policy_code = data[@"policy_code"];         company = data[@"company"];     }         return self; }     @end 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -