in Education by
I'm stuck at the point of parsing a JSON array of dicts (http://www.cjs-design.nl/json.php) into a tableview. I just want to display the title's first, ill figure out detailviews later. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } NSString *rawJson = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.cjs-design.nl/json.php"]]; // No connection or file not found if ([rawJson length] == 0) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Foutmelding" message:@"De URL kon niet worden gevonden" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; [alert show]; [alert release]; [rawJson release]; return; } SBJSON *parser = [[[SBJSON alloc] init] autorelease]; // 1. get the top level value as a dictionary NSDictionary *jsonObject = [parser objectWithString:rawJson error:NULL]; // 2. get the object as an array NSArray *list = [jsonObject objectForKey:@"book"]; // 3. iterate the array; each element is a dictionary. for (NSDictionary *book in list) { // that contains a string for the key "title" NSString *title = [book objectForKey:@"title"]; cell.textLabel.text = title; } return cell; } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Somewhere i.e. viewDidLoad, you need to parse your JSON. Then implement UITableView's dataSource methods. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [list count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CellIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } NSDictionary *book = [list objectAtIndex:indexPath.row]; NSString *title = [book objectForKey:@"title"]; cell.titleLabel.text = title; }

Related questions

0 votes
    I am using filbeat to send logs to logstash and then store them in elasticsearch. My logs file contains ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I have been wrestling with this for a while. I am trying to parse a JSON Api into a UITableview. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I am inserting JSON string into table, than on listing page in View inside foreach loop I want to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I have one column in my table which will store data in string format the sample data is {"pre- ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    In java, how can I parse json text to get value of variables like post_id ? Here is my json text { "page": { ... ": "1234567890" } ] } Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    This my my JSON: { "maps": [ { "id": "AT", "iscategorical": "0" }, { "id": "AT", "iscategorical": "0 ... the values, How can I do it? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    What is the purpose of the method JSON.parse()? (a) Parses a string to integer (b) Parses a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    What are the parameters of the method JSON.parse()? (a) text (b) reviver (c) both text and ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    Why can't we Python parse this JSON data?...
asked Jan 11, 2021 by JackTerrance
0 votes
    If we need to parse a JSON string in JavaScript. The response is something like var response = '{"result":true,"count":1}'; How can we get the values result and count from this?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    I have Conversation classes with a members relation attribute pointing to User class. This members attribute consists ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I have a CLOB column with the following data (simplified for the purposes of this question) { "notUsed" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I was unable to find a solution that is identical with the issue I am trying to solve. If is a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I have the following stored in an Oracle database as JSON: { value: [1,2,3] } The value can be ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
...