i fetched json , in json dictionary image, name, url. want comment in json dictionary , reload in tableview
. tried null value. please how comment , reload in tableview. please below check code , tell wrong. thank you.
my json
( { image = "http://sixthsenseit.com/school/project/uploades/160223032210.png"; likes = 3; name = "radhika saxena"; url = "http://sixthsenseit.com/school/my-school/uploads/photo_1448551101.jpg"; }, { comment = ( { comment = q; name = ""; }, { comment = f; name = ""; }, { comment = ffgggggggg; name = ""; }, { comment = vcvg; name = ""; }, { comment = ggg; name = ""; }, { comment = aad; name = ""; }, { comment = anku; name = ""; }, { comment = gffgffg; name = ""; }, { comment = fggg; name = ""; }, { comment = vgghj; name = ""; }, { comment = ffgfh; name = testing; }, { comment = bnvib; name = "harshali sharma"; } ); } )
get response in viewdidload
nsmutableurlrequest *request = [[nsmutableurlrequest alloc] initwithurl:[nsurl urlwithstring:@"http://sixthsenseit.com/school/project/ios/image_data.php"]]; //create method "get" or "post" [request sethttpmethod:@"post"]; //pass string server(you should give parameters instead of parameters) nsstring *userupdate =[nsstring stringwithformat:@"pid=%@&uid=%@&",@"29",@"1000710017", nil]; //check value passed // nslog(@"the data details =%@", userupdate); //convert string data nsdata *data1 = [userupdate datausingencoding:nsutf8stringencoding]; //apply data body [request sethttpbody:data1]; //create response , error nserror *err; nsurlresponse *response; nsdata *responsedata = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&err]; nsarray *json = [nsjsonserialization jsonobjectwithdata:responsedata options:kniloptions error:&err]; nslog(@"results == %@",json); _name.text = [[json objectatindex:0]objectforkey:@"name"]; image = [[json objectatindex:0]objectforkey:@"url"]; nsurl *url = [nsurl urlwithstring:image]; nsdata *imagedata = [nsdata datawithcontentsofurl:url]; _image.image = [uiimage imagewithdata:imagedata]; url = [[json objectatindex:0]objectforkey:@"image"]; nsurl *urls = [nsurl urlwithstring:url]; nsdata *imagedatas = [nsdata datawithcontentsofurl:urls]; _url.image = [uiimage imagewithdata:imagedatas]; comment_ary = [json valueforkey:@"comment"];
tableview methods
- (nsinteger)numberofsectionsintableview:(uitableview *)tableview { return 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return [comment_ary count]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { //nslog(@"tableview cell"); commentcell *cell = [tableview dequeuereusablecellwithidentifier:@"htrcell"]; if (cell==nil) { nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"cell" owner:self options:nil]; cell = [nib objectatindex:0]; } nsdictionary *getvalues = comment_ary [indexpath.row]; cell.name.text=[nsstring stringwithformat:@"%@",getvalues [@"name"]]; cell.comment.text=[nsstring stringwithformat:@"%@",getvalues[@"comment"]]; return cell; }
you need comment second object of nsarray
json , after reload tableview
.
self.comment_ary = [[json objectatindex:1] objectforkey:@"comment"]; [self.tableview reloaddata];
Comments
Post a Comment