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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:46:45+00:00 2026-05-24T21:46:45+00:00

I am trying to get a JSON to iOS app, but keep getting NULL

  • 0

I am trying to get a JSON to iOS app, but keep getting NULL values..

- (id)initWithDictionary:(NSDictionary *)dictionary {
    self.name      = [dictionary valueForKey:@"name"];
    self.amount    = [NSString stringWithFormat:@"%@", 
                      [dictionary valueForKey:@"amount"]];
    self.goalId    = [dictionary valueForKey:@"id"];
    self.createdAt = [dictionary valueForKey:@"created_at"];
    self.updatedAt = [dictionary valueForKey:@"updated_at"];
    return self;
}
+ (NSArray *)findAllRemote {
    NSURL *url = [NSURL URLWithString:@"http://localhost:3000/goals.json"];
    NSError *error = nil;
    NSString *jsonString = 
    [NSString stringWithContentsOfURL:url 
                         encoding:NSUTF8StringEncoding 
                            error:&error];

    NSLog(@"my string = %@",  jsonString);

   NSMutableArray *goals = [NSMutableArray array];
   if (jsonString) {
       SBJSON *json = [[SBJSON alloc] init];    
       NSArray *results = [json objectWithString:jsonString error:&error];

       [json release];


       for (NSDictionary *dictionary in results) {
           Goal *goal = [[Goal alloc] initWithDictionary:dictionary];
           [goals addObject:goal];
           [goal release];
        }
    }
    return goals;    
}

JSON string looks correct:

my string = [{“goal”:{“amount”:”100.0″,”created_at”:”2011-08-20T00:55:34Z”,”id”:1,”name”:”User”,”updated_at”:”2011-08-20T00:55:34Z”}},{“goal”:{“amount”:”200.0″,”created_at”:”2011-08-20T00:56:48Z”,”id”:2,”name”:”User2″,”updated_at”:”2011-08-20T00:56:48Z”}},{“goal”:{“amount”:”19999.0″,”created_at”:”2011-08-20T19:15:10Z”,”id”:3,”name”:”This is MY GOAL”,”updated_at”:”2011-08-20T19:15:10Z”}},{“goal”:{“amount”:”0.0″,”created_at”:”2011-08-20T20:46:44Z”,”id”:4,”name”:”goal”,”updated_at”:”2011-08-20T20:46:44Z”}}]

I am missing something basic I guess..

UPDATE:

Here is a line that returns NULL (from another class):

- (IBAction)refresh {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
self.goals = [Goal findAllRemote];
[self.tableView reloadData];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

- (void)viewDidLoad
{
[super viewDidLoad];

self.title = @"Goals";
self.navigationItem.leftBarButtonItem = self.editButtonItem;

UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] 
                                      initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                  target:self 
                                  action:@selector(refresh)];
self.navigationItem.rightBarButtonItem = refreshButton;
[refreshButton release];

[self refresh];

}


 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


static NSString *CellIdentifier = @"GoalCellId";

UITableViewCell *cell = 
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
                                   reuseIdentifier:CellIdentifier] autorelease];
}

Goal *goal = [goals objectAtIndex:indexPath.row];

cell.textLabel.text = goal.name;
cell.detailTextLabel.text = goal.amount;

return cell;
}

goal.name and goal.amount are Null..

  • 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-24T21:46:46+00:00Added an answer on May 24, 2026 at 9:46 pm

    This may not be part of your issue, but you should be calling [self init] (or more importantly, [super init] via inheritance):

    - (id)initWithDictionary:(NSDictionary *)dictionary {
        if (self = [self init]) {
          self.name      = [dictionary valueForKey:@"name"];
          self.amount    = [NSString stringWithFormat:@"%@", 
                          [dictionary valueForKey:@"amount"]];
          self.goalId    = [dictionary valueForKey:@"id"];
          self.createdAt = [dictionary valueForKey:@"created_at"];
          self.updatedAt = [dictionary valueForKey:@"updated_at"];
        }
        return self;
    }
    

    Also:

        for (NSDictionary *dictionary in results) {
           Goal *goal = [[Goal alloc] initWithDictionary:
              [dictionary objectForKey:@"goal"]];
           [goals addObject:goal];
           [goal release];
        }
    

    Key change is [dictionary objectForKey:@"goal"] in line 3.

    The JSON array is of objects with a single goal member, with the properties that your initWithDictionary method is looking for.

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

Sidebar

Related Questions

I am trying this to get json object but it does not seem to
Hi i'm trying to get the content from a json file, but i can't
i am trying to get only JSON response from a webservice. i am getting
I am trying to connect my iOS app to a GET data from my
I am trying to get backbone.js to load json. The json loads but i
I'm trying to get a JSON object like: { username: clelio, name: Clelio de
I'm trying to get JSON data to turn it into html but the JSON
I am trying to get json data but I am not able to do
Trying to get a JSON output to work with jqGrid 'userdata' option. The example
While trying to GET a JSON, my callback function is NOT firing. $.ajax({ type:GET,

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.