Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6855141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:43:12+00:00 2026-05-27T01:43:12+00:00

I have fetched Json with JSONKit from url to NSDictionary in initWithNibName NSData *jsonData

  • 0

I have fetched Json with JSONKit from url to NSDictionary in initWithNibName

    NSData *jsonData = [NSData dataWithContentsOfURL:[NSURL URLWithString:jsonUrl]];
    JSONDecoder *jsonKitDecoder = [JSONDecoder decoder];
    jsonDic = [jsonKitDecoder parseJSONData:jsonData];    // NSDictionary *jsonDic
    NSLog(@"Json Dictionary Fetched %@", jsonDic); // Display the Json fine :-)
    NSLog(@"Dictionary Count %i", [jsonDic count]); // Display the Dic count fine :-)
    array = [jsonDic objectForKey:@"courses"];    // NSArray *array
    NSLog(@"Courses Found %@", array); // Display the array fine :-)
    NSLog(@"Courses Count %i", [array count]);

Here is the Json

    { "name":"Name 1" , "courses": [
        { "title":"Course 1" , "desc":"This is course 1" }, 
        { "title":"Course 2" , "desc":"This is course 2" }, 
        { "title":"Course 3" , "desc":"This is course 3" }  ]
    }

I dragged a tableview to xib. set IBOutlet UITableview tblView to the tableview in Connections on Interface Builder and aslo the the tableview dataSource and delegate to FilesOwner

manually added the tableview events as

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 1;
    }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        int cnt = [array count];    // CRASHES HERE Remeber returning 1; still why ?
        return 1;
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {     
        static NSString *CellIdentifier = @"Cell";   
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        }
        int indx = [indexPath indexAtPosition:1];
        /* THESE ARE ALL COMMENTED
        NSString *key = [[jsonDic allKeys] objectAtIndex:indx];
        NSString *value = [jsonDic objectForKey:key];
        cell.textLabel.text = value;
        /* / THESE ARE ALL COMMENTED
        NSDictionary *eachItem = [array objectAtIndex:indx];
        cell.textLabel.text = [eachItem objectForKey:@"title"];
        // */
        cell.textLabel.text = @"My Title"];
        return cell;
    }

Someone please help me on this. I need to display the Courses on tableview.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:43:13+00:00Added an answer on May 27, 2026 at 1:43 am

    Your array object is probably deallocated leading to a crash (EXEC_BAD_ACCESS?) if you send a message (here count) to it. From the line

    array = [jsonDic objectForKey:@"courses"];    // NSArray *array
    

    It seems like it is autoreleased, you should retain it.

    EDIT:

    You can retain it by:

    Setting it as a retain property

    @property(nonatomic, retain) NSArray* array;
    

    and using the accessor

    self.array = [jsonDic objectForKey:@"courses"]; 
    

    which automatically releases the old value and retains the new one. Or by retaining it explicitely

    array = [[jsonDic objectForKey:@"courses"] retain];
    

    then you must not forget to release it when you are done or you will leak memory. You should read the Advanced Memory Management Programming Guide, it gives you a thorough explanation, and it is quite crucial that you understand the basic techniques.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’m new to android,I have an activity class which fetches Json string from url
I have an array of objects which was fetched from a JSON (JSONP) file
I have a list of JSON generated data, fetched from a MySQL database. What
I have a resource which is fetched from a JSON API. The JSON is
I have fetched some records from core data, and presented it in a table
I have this NodeJS app which fetches JSON-type response from a web application and
I have a json object: images:{1:{imagename:image1.gif,url:image1url},2:{imagename:image2.gif,url:image2url},3:{imagename:image3.gif,url:image3url}} I want to fetch imagename and url from
Ok, so I have a script to fetched images from Google's Picasa image service
I am using Ember.js to create a table from a json feed. I have
I have to return data fetched from MySQL table into a php file as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.