Witam.
Nie wiem jak odwołać się do pliku JSON, aby wyświetlił się na symulatorze w TableView. Wyświetla mi się poprawnie plik w konsoli, Poniżej znajduje się kod, który napisałem:
#import "WordsViewController.h"
#import "Word.h"
@interface WordsViewController ()
@end
@implementation WordsViewController
@synthesize jsonArray, wordsArray;
- (void)viewDidLoad {
[super viewDidLoad];
//set the title of our VC
self.title = @"SŁOWNIK";
//LOAD DATA
[self simpleJsonParsing];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
return cell;
}
- (void)simpleJsonParsing
{
//-- Make URL request with server
NSHTTPURLResponse *response = nil;
NSString *jsonUrlString = [NSString stringWithFormat:@"https://uidictionary.herokuapp.com/phrases.json"];
NSURL *url = [NSURL URLWithString:[jsonUrlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//-- Get request and response though URL
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
//-- JSON Parsing
NSMutableArray *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:nil];
NSData * data = [NSData dataWithContentsOfURL:url];
NSLog(@"Result = %@",result);
// for(NSDictionary *review in )
// [self.tableView reloadData];
// for (NSMutableDictionary *dic in result)
// {
// NSString *string = dic[@"array"];
// if (string)
// {
// NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
// dic[@"array"] = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
// }
// else
// {
// NSLog(@"Error in url response");
// }
// }
}
@end