xcode web service array

//  StudentViewController.m

//  MyWebService
//
//  Created by mac on 7/11/56 BE.
//  Copyright (c) 2556.  All rights reserved.
//
#import "StudentViewController.h"

@interface StudentViewController ()
@end
@implementation StudentViewController
@synthesize studentArray;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated
{
NSString *urlstring = @"http://192.168.99.200/getallstudents";
NSURL *url = [NSURL URLWithString:urlstring];
NSError *error;
NSString *json = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:&error];
NSLog(@"Error: %@", error);
//show data from array using method getallstudents
NSData *jsondata=[json dataUsingEncoding:NSASCIIStringEncoding];
studentArray=[NSJSONSerialization JSONObjectWithData:jsondata options:kNilOptions error:&error];
[self.tableView reloadData];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return studentArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *student=[studentArray objectAtIndex:indexPath.row];[cell.textLabel setText:[student objectForKey:@"firstname"]];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}
@end
---------------------------------------------------------------------------------------------

//  MyWebService

//  Created by mac on 7/11/56 BE.
//  Copyright (c) 2556. All rights reserved.
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)callWebService:(id)sender {
NSString *urlstring = @"http://192.168.99.200/getallstudents";
NSURL *url = [NSURL URLWithString:urlstring];
NSError *error;
NSString *json = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:&error];
NSLog(@"Error: %@", error);
UIAlertView *a= [[UIAlertView alloc] initWithTitle:@"Result" message:json delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[a show];
//show data from array using method getallstudents
NSData *jsondata=[json dataUsingEncoding:NSASCIIStringEncoding];
NSMutableArray *jsonarray=[NSJSONSerialization JSONObjectWithData:jsondata options:kNilOptions error:&error];
NSLog(@"Array: %@", jsonarray);

//data is object using NSDictionary but data is array using NSArray
//show data from array using method getstudent
/*NSData *jsondata=[json dataUsingEncoding:NSASCIIStringEncoding];

NSDictionary *jsondict=[NSJSONSerialization JSONObjectWithData:jsondata options:kNilOptions error:&error];
NSLog(@"Data: %@",jsondict);
NSLog(@"Student Name %@ %@",[jsondict objectForKey:@"firstname"],[jsondict objectForKey:@"lastname"]);*/
}
@end

----------------------------------------------------------------------------------------------------

Screen Shot 2556-07-12 at 9.20.23 AM

Screen Shot 2556-07-11 at 3.18.04 PM Screen Shot 2556-07-11 at 3.18.12 PM