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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:22:25+00:00 2026-05-26T07:22:25+00:00

For my project I have built my own api using PHP. The result of

  • 0

For my project I have built my own api using PHP. The result of json encoding basically gives me an array of entries like below

{"terms":[
           {"term0":
               {"content":"test id",
                "userid":"100","translateto":null,
                "hastranslation":"0",
                "created":"2011-10-19 16:54:57",
                "updated":"2011-10-19 16:55:58"}
               },
           {"term1":
               {"content":"Initial content",
                "userid":"3","translateto":null,
                "hastranslation":"0",
                "created":"2011-10-19 16:51:33",
                "updated":"2011-10-19 16:51:33"
               }
           }
         ]
}

However, I’ve been having problems working with NSMutableDictionary and extracting “content” in Objective-C.

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

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

if (JSONval != nil) {
    NSMutableDictionary *responseDataDict = [JSONval objectForKey:@"terms"];
    if (responseDataDict!= nil) {
        for (id key in responseDataDict) {
            NSString *content = [[responseDataDict objectForKey:key]objectForKey:@"content"];
            [terms addObject:content];
            textView.text = [textView.text stringByAppendingFormat:@"\n%@", content];
        } 
        button.enabled = YES;
    }
}

}

Where NSLog spits out error when I send objectForKey to responseDataDict, which is a __NSArrayM according to the log.

What did I do wrong here?

  • 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-26T07:22:26+00:00Added an answer on May 26, 2026 at 7:22 am

    NSMutableDictionary *responseDataDict = [JSONval objectForKey:@”terms”];

    But the value of "terms" isn’t a dictionary; it’s an array. Note the square brackets in your JSON string. You should use:

    NSArray *terms = [JSONval objectForKey:@"terms"];
    

    instead.

    Note that each term in the array is an object (a dictionary) containing a single name (key) whose corresponding value (object) is, in turn, another object (dictionary). You should parse them as:

    // JSONval is a dictionary containing a single key called 'terms'
    NSArray *terms = [JSONval objectForKey:@"terms"];
    
    // Each element in the array is a dictionary with a single key
    // representing a term identifier
    for (NSDictionary *termId in terms) {
        // Get the single dictionary in each termId dictionary
        NSArray *values = [termId allValues];
    
        // Make sure there's exactly one dictionary inside termId
        if ([values count] == 1) {
            // Get the single dictionary inside termId
            NSDictionary *term = [values objectAtIndex:0];
    
            NSString *content = [term objectForKey:@"content"]
            …
        }
    }
    

    Add further validation as needed.

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

Sidebar

Related Questions

I have a project built and packaged with a specific version of jsp-apiand servlet-api
I have built a web setup project in VS2008 which installs my ASP.NET/Silverlight app
I have a project that is built and managed by Maven. I have a
I have a project that comprises pre-build Dll modules, built some time in the
I have a .NET project which references another assembly that is built outside of
I have Android pet-project DroidIn which utilizes HttpClient 4 (built into Android) to do
I have an exe that is built and placed into a Setup project for
I have a small RIA that I built as a learning/make-my-life-easier project that uses
I have pretty sophisticated build using gradle - with a number of own gradle
I have put together a HTTP driven API using the WCF WebAPI that uses

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.