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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:18:19+00:00 2026-05-24T05:18:19+00:00

This is a strange error and I’m not sure if I’m using JSON correctly.

  • 0

This is a strange error and I’m not sure if I’m using JSON correctly. When I get a response from the server with a proper array, JSON chews it up, turning most of the values to zero and I think it might’ve forgotten by keys also.

2011-08-01 16:08:15.981 My Alerts[2746:b303] From Server: {"cycleStart":"May 1, 2011","cycleEnds":"May 29, 2011","avg_usage":0,"estimate":0,"totalBudget":0,"Usage":0,"Cost":0}
2011-08-01 16:08:15.982 My Alerts[2746:b303] After JSON: (
   0,
   0,
   0,
   0,
   "May 29, 2011",
   "May 1, 2011",
   0
)

Here is my code showing where JSON is being used.

NSString *post = [NSString stringWithFormat:@"username=%@&acct=%@", username, account];
NSLog(@"POST: %@", post);
NSData *postData = [NSData dataWithBytes: [post UTF8String] length: [post length]];

// Submit login data
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString: @"http://***.****.***/file1.php"]];
[request setHTTPMethod: @"POST"];
[request setValue: @"application/x-www-form-urlencoded" forHTTPHeaderField: @"Content-Type"];
[request setHTTPBody: postData];

// Retreive server response
NSURLResponse *response;
NSError *err;
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
if (returnData == nil) {
    NSLog(@"ERROR: %@", err);
}

NSString *content = [NSString stringWithUTF8String:[returnData bytes]];
NSLog(@"From Server: %@", content); // <---JSON string returned perfectly from server

if (content != @"FAIL")
{
    NSArray *viewDetail = [[NSArray alloc] init];
    viewDetail = [[[content JSONValue] allValues] mutableCopy]; // <--JSON appears to be chewing it up
    NSLog(@"After JSON: %@", viewDetail); // <--Array is now messed up here.

    // Do stuff with viewDetail array

    [viewDetail release];
}
  • 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-24T05:18:20+00:00Added an answer on May 24, 2026 at 5:18 am

    I can’t see what’s wrong. You wanted allValues, you got all the values. Aside from the ordering, the “from server” and “after JSON” are equivalent.

    The ordering is not there because NSDictionary (which your JSONValue returns, I believe) does not guarantee order. And the keys are not there because you did not request keys, you requested the values.

    If you wanted keys, there’s allKeys method. And if you wanted a specific value, there’s objectForKey: or valueForKey:. You can also use various enumerators. For instance, I believe this should work:

    NSDictionary *dict = [content JSONValue];
    for (id key in dict) {
        NSLog(@"key: %@   value:%@", key, [dict objectForKey:key]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Entity Framework, I suddenly get this strange error after publishing my asp.net mvc
I created a Hello world app but get this strange error: The project cannot
I'm making a TCP Client in Applet mode and I get this strange error...
While setting up Sphinx on my production server, this strange error came up when
I get this strange error if I use a link_to with the :remote =>
I'm getting this strange error using Rails 3.0.2. ActionView::Template::Error (undefined method `parent' for nil:NilClass):
I'm getting a strange error from the Python interpreter when I run this code:
I have this strange error in SQL Server 2005 where I take a working
I get this strange error child pid 1789 exit signal Bus error (10) I
Right now I'm getting this strange error from IE which is basically 'null' is

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.