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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:01:30+00:00 2026-05-26T23:01:30+00:00

Never touched json before. I’m trying to access some variables within the Wunderground weather

  • 0

Never touched json before. I’m trying to access some variables within the Wunderground weather API for Melbourne. For example, let’s say I want to access the “wind_dir”:”East” variable. This is my code thus far:

NSString *urlString = 
    [NSString stringWithFormat:
     @"http://api.wunderground.com/api/key/geolookup/conditions/forecast/q/-33.957550,151.230850.json"];

    NSLog(@"URL = %@", urlString);

    SBJsonParser *parser = [[SBJsonParser alloc] init];

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];

    NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

    NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];

    NSArray *weatherInfo = [parser objectWithString:json_string error:nil];

    for (NSDictionary *weatherString in weatherInfo)
    {

        NSLog(@"some weather info = %@", [[[weatherString objectForKey:@"response"] objectForKey:@"current_observation"] objectForKey:@"wind_dir"]);

    }

My code reaches the for loop and crashes with this error: -[NSCFString objectForKey:]: unrecognized selector sent to instance.

I’m not 100% sure what’s causing the crash, and whether my path to the “wind_dir” variable is correct, though they could well be the same problem.

Thanks in advance for any help.

  • 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-26T23:01:31+00:00Added an answer on May 26, 2026 at 11:01 pm

    either the “response” property or the “current_observation” propery is string and not dictionary.

    the error you are getting is that you are trying to call “objectForKey” on a string.

    after looking at the result of the API, it seems that you are not getting an array.

    You should do something like this:

        NSDictionary *weatherInfo = [parser objectWithString:json_string error:nil];
    
        NSLog(@"some weather info = %@", [[weatherInfo objectForKey:@"current_observation"] objectForKey:@"wind_dir"]);
    

    instead of your for statement.

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

Sidebar

Related Questions

Background: I'm new to Objective-C and I've never touched C before. I'm trying to
I've never touched threads before, and by the looks of it I might have
I have never programmed anything in php before and haven't touched html in 10
Trying to install the new Rails 3 release on OSX 10.6. Have never touched
every time i code a gui (in my case with GWT, never touched gui
Never used a cache like this before. The problem is that I want to
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
Ive never heard of this before, and I have been coding in PHP for
I never did any serious Java coding before, but I learned the syntax, libraries,
Greetings, I'm no XSL/XSLT/XML shark, I have worked with some, though, but I've never

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.