0

我正在使用以下JSON值,我需要将此值显示为UITableview

请帮我。

{"id":"58","appVersionId":"1102","averageRating":"4.0","reviews":{"reviews":[{"id":"58","userId":"1","reviewTitle":"Good application","reviewText":"nice","rating":"4.0","createdDate":"2013-02-11T00:00:00+08:00"},{"id":"102","userId":"252","reviewTitle":"Good","rating":"4.0","createdDate":"2013-02-13T00:00:00+08:00"}]}}
4

1 回答 1

1

从链接下载 SBJSon 库

导入这些文件

 #import "JSON.h"

 #import "SBJsonParser.h"

jsonurl=[NSURL URLWithString:@"http://sample.com/sample.php"]; //NSUrl declared in .h

jsondata=[[NSString alloc]initWithContentsOfURL:jsonurl encoding:NSUTF8StringEncoding error:&error];//NSData 
jsonarray=[[NSMutableArray alloc]init]; //NSmutableArray

self.jsonarray=[jsondata JSONValue];


 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
     UILabel *description=[[UILabel alloc]initWithFrame:CGRectMake(5, 0, 210,44 )];
     description.text=[NSString stringWithFormat: @"%@",[[jsonarray objectAtIndex:indexPath.row] valueForKey: @"id"]];
     [description setFont:[UIFont systemFontOfSize:14]];
     description.backgroundColor=[UIColor clearColor];
     description.textColor=[UIColor whiteColor];
     // description.textColor=[UIColor colorWithRed:79.0f/255.0f green:66.0f/255.0f blue:55.0f/255.0f alpha:1];
     description.numberOfLines=3;
     [cell.contentView addSubview:description];
}


return cell;

 }

希望这可以帮助!!!

于 2013-02-13T07:13:04.920 回答