Hi could someone please point me into the right direction.I am trying to display the data from website to the uotableviw using json
my response looks like this in the console:
Code:
2010-09-14 00:11:59.620 testjson[3435:207] (
{
ItemAuthor = Book1;
ItemName = "Author1";
},
{
ItemAuthor = Book2;
ItemName = author2;
},
{
ItemAuthor = "Edward de Bono";
ItemName = "How to Have a Beautiful Mind";
}
now in the viewDidLoad I have for test only the folowing code:
Code:
- (void)viewDidLoad {
NSString *scoreURL;
scoreURL = [NSString stringWithFormat:@"http://fireball.zeon/test-json.php", @""];
NSLog(@"%@",scoreURL);
//start making the connection here
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:scoreURL]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
// create the connection with the request
theConnection =[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection)
// start loading the data
// Create the NSMutableData to hold the received data.
responseData = [[NSMutableData data] retain];
}
In the connection finish loading I have the following code:
Code:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
//check if the user returned the correct data
jsonArray = [responseString JSONValue];
NSLog(@"%@",jsonArray);
//NSLog(@"%i",[jsonArray count]);
[responseString release];
[self.tableView reloadData];
}
I have a rootviewcontroller with a tableview at the moment I am trying to do something like this:
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
cell.textLabel.text = [self.jsonArray objectAtIndex:indexPath.row];
// Set up the cell
return cell;
}
But I do not get anything displayed in the table.
Could anyone show me the correct way to bind the response to the table.
many thanks in advance