Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
JSON data is something like that..
JavaScript
{"order_list_1":[
{"name":"@SEVEN (7) OCLOCK BLADE PLATINUM","qty":1,"mrp":1.0},
{"name":"ACT 2 POPCORN BUTTER PEPPER","qty":2,"mrp":2.0},
{"name":"ACT 2 POPCORN CHILLY SURPRISE","qty":3,"mrp":3.0},
{"name":"@MAGGI SOUP HOT N SOUR(1 1)","qty":4,"mrp":4.0},
{"name":"ACT 2 POPCORN GOLDEN SIZZLE","qty":5,"mrp":5.0},
{"name":"AMCHUR AAKHA 1kg","qty":6,"mrp":6.0}]
}

jSon data is displaying on console but not on tableview..

Here my code snipest...

C#
(void)fetchData{
dispatch_async(bKQueue, ^{
    NSData *data = [NSData dataWithContentsOfURL:latestURL];

    NSLog(@"LatestURL:%@",latestURL);       
    NSError* error=nil;  

    //Creating JSON Object
    NSDictionary *jsonDict= [NSJSONSerialization JSONObjectWithData:data  options:kNilOptions error:&error];

    NSLog(@"JSON = %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);

    //NSLog(@"dataaaa :%@",jsonDict);

    dispatch_async(dispatch_get_main_queue(), ^{

     //[self fetchData:responseData];
     [self.tableView reloadData];
     //NSLog(@"Value :%@",data);
     });

    NSDictionary *statuses=[jsonDict objectForKey:@"order_list_1"];

    NSLog(@"SomeStatus :%@",statuses);

    if (!statuses)
     {
        NSLog(@"Error in Json :%@",error);
     }
    else
    {
        for(NSDictionary *newValu in statuses)
    {
            NSString *name=[newValu objectForKey:@"name"];
            NSString *qty=[newValu objectForKey:@"qty"];
            NSString *mrp=[newValu objectForKey:@"mrp"];
            NSLog(@"Name :%@    Quantity :%@    MRP :%@ ",name,qty,mrp);
        }
    }
});
}

C#
And this is my Tableview code..

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {



 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}



NSError *error=nil;
NSDictionary *jsonDict=[NSJSONSerialization JSONObjectWithData:responseData      options:kNilOptions error:&error];
NSArray *statuses=[jsonDict objectForKey:@"order_list_1"];
for (int i=0; i<jsonDict.count; i++) {
    NSDictionary *newDict=[statuses objectAtIndex:i];
NSLog(@"name :%@",[newDict valueForKey:@"name"]);
}
NSDictionary *text=[statuses objectAtIndex:indexPath.row];
cell.textLabel.text=[text objectForKey:@"name"];
cell.textLabel.text=[text valueForKey:@"qty"];
cell.textLabel.text=[text valueForKey:@"mrp"];


[self.tableView reloadData];
return cell;
}
Posted
Updated 12-Jun-12 21:06pm
v6

1 solution

cellForRowAtIndexPath is called for each row in the table. And number of rows are specified by implementing the method -
C++
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 


So specify number of rows in this method and call [self.tableView reloadData]; before exiting fetchData method, not in cellForRowInIndexPath. I hope this will help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900