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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:16:15+00:00 2026-05-31T17:16:15+00:00

Update: I just tested my JSON format returned from the server using JSONlint and

  • 0

Update: I just tested my JSON format returned from the server using JSONlint and it is fine.

I’m getting an exception with NSJSONSerialization in an AFNetworking call to a php script that returns JSON data. I’ve looked at the other questions here with the same issue and tried those solutions but am still getting the error.

It crashes on this line:

 NSError *e = nil;
 NSMutableArray *jsonArray = 
 [NSJSONSerialization JSONObjectWithData: jsonData 
                                 options: NSJSONReadingMutableContainers 
                                   error: &e];

Error Log:

2012-03-19 18:10:41.291 imageUploader[3538:207] * Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSCFArray bytes]: unrecognized selector sent to instance 0x6867430’

My JSON data, when I call the php script through the browser looks like this:

[{“user”:”binky”,”path”:”binky-0a96f9aab5267c8.jpg”,”index”:”101″},{“user”:”binky”,”path”:”binky-9cf844252c28553.jpg”,”index”:”102″},{“user”:”binky”,”path”:”binky-d6c749d25d33015.jpg”,”index”:”103″}]

The NSLog of the data looks like this:

(
{
index = 101;
path = “binky-0a96f9aab5267c8.jpg”;
user = binky;
},
{
index = 102;
path = “binky-9cf844252c28553.jpg”;
user = binky;
},
{
index = 103;
path = “binky-d6c749d25d33015.jpg”;
user = binky;
} )

Finally, I do a test to make sure I have valid JSON data:

         if ([NSJSONSerialization isValidJSONObject: jsonData]){
             NSLog(@"Good JSON \n");
         }

So I can’t understand where the source of my error is. Little help?

// AFNetworking operation + block

    AFJSONRequestOperation *operation = 
    [AFJSONRequestOperation JSONRequestOperationWithRequest:myRequest 
     success:^(NSURLRequest *request, NSHTTPURLResponse *response, id jsonData) {

         NSLog(@"Success JSON data:\n %@ \n", jsonData); //log data

         if ([NSJSONSerialization isValidJSONObject: jsonData]){
             NSLog(@"Good JSON \n");
         }

         NSError *e = nil;
         NSMutableArray *jsonArray = [NSJSONSerialization JSONObjectWithData: jsonData options: NSJSONReadingMutableContainers error: &e];

         if (!jsonArray) {
             NSLog(@"Error parsing JSON: %@", e);
         } else {
             for(NSDictionary *item in jsonArray) {
                 NSLog(@"Item: %@", item);
             }
         }

         [self.navigationController popToRootViewControllerAnimated:YES];
     } 
     failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {

         NSLog(@"Error: %@", error);
         [self.navigationController popToRootViewControllerAnimated:YES];
     }];
  • 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-31T17:16:17+00:00Added an answer on May 31, 2026 at 5:16 pm

    Aparently JSONObjectWithData expects NSData rather than an array.
    id jsonData seems to be an Array representing the content of your json string. Aparently you are expecting an Array anyway.

    For some reason you are doing it twice. Instead of

     NSMutableArray *jsonArray = [NSJSONSerialization JSONObjectWithData: jsonData options: NSJSONReadingMutableContainers error: &e];
    

    you could simply use

    NSMutableArray *jsonArray = [NSMutableArray arrayWithArray:jsonData];
    

    or, if it does not have to be mutable:

    NSArray *jsonArray = (NSArray *) jsonData;
    

    However, you should always test whether it is really an array in jsonData. Depending on the structure within the json string it could be an NSDictionary or nil in case of errors.

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

Sidebar

Related Questions

I was just reading an update from a friend's project, mentioning the use of
How can I update an entity effectively in hibernate just as by using SQL.
I am using .Net3.5. Just wondering my understanding about the insert, update, delete are
UPDATE: So pretty much everyone here has told me that I just need to
I just installed Eclipse Galileo for Java developers and noticed that the update site
Update: Last night, I decided that this is just too much work to change
I've just used it for the first time - consider: IGameObject void Update() IDrawableGameObject
How can I update this regular expression to find and replace not just /news/
Update: Based on a couple of the answers I have received, I just want
UPDATE: SOLVED Hi all, i've got it, just save cookie to temp file, and

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.