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

  • Home
  • SEARCH
  • 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 6857669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:03:20+00:00 2026-05-27T02:03:20+00:00

I created a web service which returns JSON or so I think. The data

  • 0

I created a web service which returns JSON or so I think. The data returned look like this:

{"invoice":{"id":44,"number":42,"amount":1139.99,"checkoutStarted":true,"checkoutCompleted":true}}

To me, that looks like valid JSON.

Using native JSON serializer in iOS5, I take the data and capture it as a NSDictionary.

NSError *error;
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:[request responseData] options:kNilOptions error:&error];
    NSLog(@"json count: %i, key: %@, value: %@", [json count], [json allKeys], [json allValues]);

The output of the log is:

json count: 1, key: (
    invoice
), value: (
        {
        amount = "1139.99";
        checkoutCompleted = 1;
        checkoutStarted = 1;
        id = 44;
        number = 42;
    }
)

So, it looks to me that the JSON data has a NSString key “invoice” and its value is NSArray ({amount = ..., check...})

So, I convert the values to NSArray:

NSArray *latestInvoice = [json objectForKey:@"invoice"];

But, when stepping through, it says that latestInvoice is not a CFArray. if I print out the values inside the array:

for (id data in latestInvoice) {
        NSLog(@"data is %@", data);
    }

The result is:

data is id
data is checkoutStarted
data is ..

I don’t understand why it only return the “id” instead of “id = 44”. If I set the JSON data to NSDictionary, I know the key is NSString but what is the value? Is it NSArray or something else?

This is the tutorial that I read:
http://www.raywenderlich.com/5492/working-with-json-in-ios-5

Edit: From the answer, it seems like the “value” of the NSDictionary *json is another NSDictionary. I assume it was NSArray or NSString which is wrong. In other words, [K,V] for NSDictionary *json = [@”invoice”, NSDictionary]

  • 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-27T02:03:21+00:00Added an answer on May 27, 2026 at 2:03 am

    The problem is this:

    NSArray *latestInvoice = [json objectForKey:@"invoice"];
    

    In actual fact, it should be:

    NSDictionary *latestInvoice = [json objectForKey:@"invoice"];
    

    …because what you have is a dictionary, not an array.

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

Sidebar

Related Questions

I'm using a web service which returns a list of products. I created a
I have created a web service which is saving some data into to db.
I've created a simple C# asp.net web service function which returns a string message
I am hosting a web service in ASP.Net MVC3 which returns a Json string.
I have created a web service which has a couple of methods developed using
I created a simple .Net web service which runs a very simple query (which
I have an existing web service that returns XML responses and I would like
I've created a WCF service which I intend to use when sending data from
I have been given the task of calling a web service which returns an
I have created a rest architecture based web service in C# which will return

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.