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 6388673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:18:29+00:00 2026-05-25T03:18:29+00:00

I did try to bring JSON data to the iPhone and connected printed the

  • 0

I did try to bring JSON data to the iPhone and connected printed the incoming JSON data using NSLOG .was able to print and test the particular node.The i started using a for-loop to loop through the Array of feed and display it in a UItableview and was not able to to do so . Tried a number of options but could not sort out this one .Please take a look at the code and let me know where and what i am doing wrong.I am still learning iPhone coding so any inout would be highly helpful.please find the code below.

#import "RootViewController.h"
#import "SBJson.h"
#import "JSON.h"

@implementation RootViewController

NSMutableArray *listOfStates;
NSArray *exercises;
NSMutableData *responseData;


- (void)viewDidLoad
{
    //---initialize the array---
    listOfStates = [[NSMutableArray alloc] init];


    responseData = [[NSMutableData data] retain];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost/~xxxx/MyWorks/index.php?playerid=0"]];
    [[NSURLConnection alloc] initWithRequest:request delegate:self ];
    //NSURL *url = [NSURL URLWithString:@""]; 

    [super viewDidLoad];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSLog(@"didReceiveResponse"); [responseData setLength:0]; }
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data]; }

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    NSLog(@"Connection failed: %@", [error description]);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    [connection release];

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    [responseData release];

    NSDictionary *dictionary = [responseString JSONValue];
    NSArray *response = [dictionary valueForKey:@"feed"];

    NSLog(@"Here is the title of the feed: %@", [response valueForKey:@"video"]);


    exercises = [[NSArray alloc] initWithArray:response];

    [[self tableView] reloadData];

}




/*
 // Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
 */

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [exercises count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    [responseData release];

    NSDictionary *dictionary = [responseString JSONValue];
    NSArray *response = [dictionary valueForKey:@"feed"];

    //create a cell
    UITableViewCell *cell = [[UITableViewCell alloc]
                             initWithStyle:UITableViewCellStyleDefault
                             reuseIdentifier:@"cell"];



    // fill it with contnets

    int ndx;
    for (ndx = 0; ndx <dictionary.count; ndx++) {
        NSDictionary *player = (NSDictionary *)[dictionary objectAtIndex:ndx];
        NSLog(@"Player: %@", [player valueForKey:@"player"]); 
    }
    NSString *cellValue = [player objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;
    // return it
    return cell;

}
  • 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-25T03:18:30+00:00Added an answer on May 25, 2026 at 3:18 am

    It’s hard to say what’s wrong without knowing what is happening, but here are a couple of observations.

    • It looks like you are parsing your response many times. Once in connectionDidFinishLoading to create the “exercises” array, and then again each time a cell is being rendered via tableView: cellForRowAtIndexPath:. I would assume that you are getting all the data you need when you first create the exercises array from JSON data. In that cases, tableView:cellForRowAtIndexPath: should just need to get the object out of the exercises array rather than dealing with the response data.
    • Also in here, I can’t figure out what you are trying to do with the loop where you use the “player” – Seems like you are logging info but not doing anything with those player objects. In addition to not using them you seem to me leaking memory with these unreleased objects.

    Based on the JSON you added in your comment, it appears that the exercises array will contain NSDictionary objects. That means your code to set the cell text is not right. Instead of

    NSString *cellValue = [response objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;
    

    you probably want something like

    NSDictionary *exercise = [response objectAtIndex:indexPath.row];
    cell.textLabel.text = [exercise valueForKey"player"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using MongoDB to bring back a record and I have the Json
Did anyone try that feature and has some feedback? Or Does anyone know some
Did anyone try to read programmatically an Alibre Design CAD file? I see that
I admit that I have almost none experience of unittesting. I did a try
I did some googling to try to answer this question but even after that
I recently installed Erlang RFC4627 (JSON-RPC) with the debian package. I ran the test
I'm using spork to test a Sinatra application and with Ruby 1.9.2 the tests
What is the easiest way to verify boost has been installed? I did try
I'm sorry if this has been asked before, but I did try digging through
Did you ever have to choose between WISA or LAMP at the beginning of

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.