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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:48:38+00:00 2026-06-17T15:48:38+00:00

When I make a JSON request with NSURLConnection, I get an unrecognized selector error

  • 0

When I make a JSON request with NSURLConnection, I get an “unrecognized selector” error [__NSCFDictionary length].

We changed from sending the request in the header as a UTF8String where it worked, to the body which requires NSData for some reason. We made that change because there will eventually be too much data for the header.

Why am I getting this error and how can I fix it? Is this somehow a problem with the object in memory? I’m baffled.

    -(void)initWebserviceWithJSONRequest:(NSData *)jsonRequest url:(NSURL *)url
    {
       //initialize the responseData property //
       self.responseData = [[NSMutableData alloc] init];
       NSError *error = nil;
       NSMutableData *requestData = [[NSMutableData alloc] init];
       requestData = [NSJSONSerialization JSONObjectWithData:jsonRequest options:NSJSONWritingPrettyPrinted error:&error];
       // create the URL request that will be passed to the NSURLConnection class // 
       NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:60];

       // set up the request values //
       [request setHTTPMethod:@"POST"];
       // line below included to show that there is a length available for requestData
       int jsonLength = requestData.description.length;// This works because it's .description.length
       [request setHTTPBody:requestData ];

       // Make a connection //
       self.connection = [NSURLConnection connectionWithRequest:request delegate:self];
    }

The call to this method is like this:

    NSData *jsonData = [[NSData alloc] initWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
    [service createWebserviceWithJSONRequest:jsonData url:loginURL];

And here is the json that I’m sending in the body:

    {
        CURRENTDATETIME = "2012-11-16 18:11:26";
        CURRENTUSERTOKEN = "";
        REQUESTDATA = "{\"USERNAME\":\"testUserName\", \"PASSWORD\":\"TestPassword\", \"APPVERSION\":\"0.001.1\", \"CARRIER\":\"ATT\", \"DEVICENAME\":\"iPad Simulator\", \"DEVICETOKEN\":\"9A384B42-7766-55AE-B61D-0AAB74A4304B\", \"OSVERSION\":\"5.1\", \"LATITUDE\":10.72182, \"LONGITUDE\":-10.148127, \"ISWIFI\":\"true\", \"BATTERYLEVEL\":42.2, \"SCREENHEIGHT\":1024, \"SCREENWIDTH\":768, \"SCREENPPI\":132, \"SIGNALSTRENGTH\":4, \"APPPACKAGE\":1003}";
        TRANSACTIONDATETIME = "2012-11-16 18:11:26";
        TRANSACTIONUSERTOKEN = "";
    }

NOTE
I’m using xcode Version 4.3.2 (4E2002)

And iOS Simulator Version 5.1 (272.21)

On Mac OS X 10.7.5

  • 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-06-17T15:48:41+00:00Added an answer on June 17, 2026 at 3:48 pm

    In general, when sending data via JSON, you’ve got some relatively complex structure in the phone (or whatever) that you want to convert to a JSON string for transmission.

    JSON strings “map” pretty well to NSDictionaries and NSArrays, so the presumption is that you get your data on the phone side into a structure of NSDictionaries and NSArrays and then pass the “root” dictionary/array to dataWithJSONObject (or, better, a different brand of JSON parser/serializer). The Apple API will return an NSData object from that conversion which can either be sent directly or converted to an NSString and sent, depending on the network interface you use.

    When/if you get JSON data back you send it through JSONObjectWithData to convert into a “nest” of NSArrays and NSDictionaries that your app can understand.

    You’ve got your inputs and outputs reversed.

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

Sidebar

Related Questions

I get the following error when I attempt to make a json post request:
I'm trying to get my head around how I can make json request to
I'm using JQuery to make a JSON request back to the server and it
I want to make call to authenticate user and get back token in json
I have an Xcode project which uses an NSURLConnection to make a request to
I'm using JQuery to make a JSON request to access data on a private
I need to make a json request with the url structure like : site.com/page?id=123
How to make HTTP Json requests in C++? Any library? Under HTTP Json request
I have to make a JSON ajax request and have an array in return.
When I make a jQuery AJAX JSON request, it responds with a d attribute.

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.