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

The Archive Base Latest Questions

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

After pounding my head all day long, I am down to StackOverflow to pull

  • 0

After pounding my head all day long, I am down to StackOverflow to pull me through.

I am making a NSURLRequest in my iPhone App …

NSURL* url = [[self serviceUrl] URLByAppendingPathComponent:[NSString stringWithFormat:@"Json"]];

NSString* json = [NSString stringWithFormat:@"{\"id\":\"%@\"}", id];

NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[urlRequest setHTTPBody:[json dataUsingEncoding:NSUTF8StringEncoding]];

this is returning to me a JSON string, which comes back to me but it is broken in the since that the string will not parse correctly.

However if I make a normal request to the same url in the Safari browser then JSON is returned correctly. I am validating this JSON here.

So whats the deal? Is there a limit to the length of data in a NSString* that a 32Kb json file would not be stored in memory correctly? Sometimes the JSON can be parsed, which leads me to believe that I am not clearing my JSON string correctly after each request.

_json = [[NSString alloc] initWithData:_dataResponse encoding:NSUTF8StringEncoding];

NSArray* retrievedData = (NSArray*)[_json JSONValue];

// removed for brevity

_json = @"";

Other information, I am using ASP.NET MVC 3 to provide the web services for this app.

EDIT

- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse 
{   
    _loader.hidden = NO;

    [_loadingIndicator startAnimating];

    return request;
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{
    _dataResponse = [[NSMutableData alloc] init];

    [_dataResponse setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{
    [_dataResponse appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{
    NSLog(@"Error receiving response: %@", error);

    _loader.hidden = YES;

    [_loadingIndicator stopAnimating];
}

- (void)connectionDidFinishLoading:(NSURLConnection*)connection 
{
    _json = [[NSString alloc] initWithData:_dataResponse encoding:NSUTF8StringEncoding];

    // Removed for brevity

    _json = @"";

    _loader.hidden = YES;

    [_dataResponse release];
    _dataResponse = nil;

    [_loadingIndicator stopAnimating];
}

FINAL SOLUTION

I was making multiple calls to have data already stored for views in order to switch views in a tab bar controller. I wasn’t checking the connection during the appending of the data, I was checking the connection when it was finished in order to store the data correctly. My final solution was to make each call sychronously after the previous one during the finished method call.

  • 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-26T16:01:46+00:00Added an answer on May 26, 2026 at 4:01 pm

    Unfortunately, nothing blatant is jumping out at me.

    Some things to try that will hopefully help:

    • double check your NSUrlConnection pattern against this doc. The only diff I see is they’re doing [[NSMutableData data] retain] instead of alloc, init. They also create NSMutableData with the connection request (not in response) and only length=0 in response. Not sure why it would matter though …

    http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html

    • try something like Charles Proxy. It allows you to sniff the wire. You can see what’s different between browser and simulator/phone access. At a minimum, you’ll see what’s coming over the wire in the bad cases.

    • add lots of logging. everytime you append data, log some details. After you convert to string and before the json call, log. Log sizes, etc… Something may offer you a hint.

    • the use of _json string seems a bit off. You’re reallocating and then setting to empty string. You should either have an iVar that you alloc and release (not set to “”) or create a @property with retain, copy.

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

Sidebar

Related Questions

Okay, after pounding my head against the wall for about 2 hours, I need
All, I'm pounding my head against the wall here. What I need is simple,
After reading the Head First Design Patterns book and using a number of other
After running the Leaks Instruments on an app that I am developing, I see
After receiving push notification app icon not display badge. In setting notification is on,
After I released my app, the in-app purchases list is not displaying in the
After switching my Rails 2.3 app from MRI Ruby 1.8.7 to JRuby 1.6.5, the
After four weeks of learning Objective-C for the iPhone, my first useful application is
After making a few changes in my application, my textures are no longer showing.
After many hours of hair pulling, I look to stackoverflow to help me solve

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.