ios - Getting (null) when I Parse the number from webservice -
i have display price of product webservice value (null)
nsarray *arr = [pjson objectforkey:@"response"]; nslog(@"%@",arr); (int i=0;i<arr.count;i++) { nsstring *thumbnail_data = [[arr objectatindex:i]objectforkey:@"img"]; nsstring *ring_data = [[arr objectatindex:i]objectforkey:@"name"]; nsstring *id_data = [[arr objectatindex:i]objectforkey:@"id"]; nsstring *cost_data = [[arr objectatindex:i]objectforkey:@"productprice"]; nslog(@"thumbnail: %@",thumbnail_data); nslog(@"author: %@",ring_data); nslog(@"author: %@",cost_data); dictionary = [nsdictionary dictionarywithobjectsandkeys: thumbnail_data, img, ring_data,name,id_data,id,cost_data,cost, nil]; [myobject addobject:dictionary]; } - (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { subcatcell =(productcollectionviewcell *)[collectionview dequeuereusablecellwithreuseidentifier:@"productcell" forindexpath:indexpath]; nsdictionary *tmpdict = [myobject objectatindex:indexpath.row]; nsmutablestring *detail; detail = [nsmutablestring stringwithformat:@"%@", [tmpdict objectforkey:name]]; // nsnumber *price = [tmpdict objectforkey:cost]; nsmutablestring *price; price = [nsmutablestring stringwithformat:@"%@", [tmpdict objectforkey:cost]]; nslog(@"%@",price); // nsmutablestring *catid; catid = [nsmutablestring stringwithformat:@"%@", [tmpdict objectforkey:id]]; nsmutablestring *images; images = [nsmutablestring stringwithformat:@"%@ ", [tmpdict objectforkey:img]]; nsurl *url = [nsurl urlwithstring:[tmpdict objectforkey:img]]; nsdata *data = [nsdata datawithcontentsofurl:url]; img= [[uiimage alloc]initwithdata:data]; subcatcell.imageview.image = img; subcatcell.lblcost.text = [nsstring stringwithformat:@"%@",price]; subcatcell.lblname.text = detail; return subcatcell; }
when nslog "cost_data" price displayed correctly when nslog "price" in cellforitemindexpath i'm getting "(null)"
may not allocated memory nsdictionary
or nsmutablearray
. kindly following changes may solved issue.
step 1 : allocate myobject
in viewdidload
myobject = [[nsmutablearray alloc] init];
step 2 : replace set of below codes.
nsarray *arr = [pjson objectforkey:@"response"]; nslog(@"%@",arr); (int i=0;i<arr.count;i++) { nsstring *thumbnail_data = [[arr objectatindex:i]objectforkey:@"img"]; nsstring *ring_data = [[arr objectatindex:i]objectforkey:@"name"]; nsstring *id_data = [[arr objectatindex:i]objectforkey:@"id"]; nsstring *cost_data = [[arr objectatindex:i]objectforkey:@"productprice"]; nslog(@"thumbnail: %@",thumbnail_data); nslog(@"author: %@",ring_data); nslog(@"author: %@",cost_data); nsdictionary* dictionary = [nsdictionary dictionarywithobjectsandkeys: thumbnail_data, @"img", ring_data,@"name",id_data,@"id",cost_data,@"cost", nil]; [myobject addobject:dictionary]; }
Comments
Post a Comment