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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:22:23+00:00 2026-06-15T03:22:23+00:00

This is my JSON output {activitiesList:{auid:19UG9IZ,comments:Please enter Description,createDate:09/19/2012 07:32:56 AM,id:19UG9IZ,owner:04256CRM,response:Missing Response,status:Assigned,type:Request Action}} The code

  • 0

This is my JSON output

{"activitiesList":{"auid":"19UG9IZ","comments":"Please enter Description","createDate":"09/19/2012 07:32:56 AM","id":"19UG9IZ","owner":"04256CRM","response":"Missing Response","status":"Assigned","type":"Request Action"}}

The code below works when I have multiple activitiesList and not for above output, which has single activitiesList

@try {
    NSError* error;
    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
    NSArray* activityListFromSiebel = [json objectForKey:@"activitiesList"]; //2
    NSLog(@" Count is %d", [activityListFromSiebel count]);
    for (int i = 0; i < [activityListFromSiebel count]; i++) {
        //if ([activityListFromSiebel count] > 1) {
            NSDictionary* completeActivity = [activityListFromSiebel objectAtIndex:i];

            ObjActivityData *dataActivity = [[ObjActivityData alloc] init];
            dataActivity.activityUID      = [completeActivity objectForKey:@"auid"];
            dataActivity.activitytype     = [completeActivity objectForKey:@"type"];
            dataActivity.activityStatus   = [completeActivity objectForKey:@"status"];
            dataActivity.activityOpenedDt = [completeActivity objectForKey:@"createDate"];
            dataActivity.activityDueDt    = @"";
            dataActivity.activityDesc     = [completeActivity objectForKey:@"comments"];
            dataActivity.activityResponse = [completeActivity objectForKey:@"response"];
            [Activities addObject:dataActivity];
            dataActivity = nil;
        //}
    }
    [self.tableView reloadData];
} @catch (NSException * e) {
    NSLog(@"catching %@ reason %@", [e name], [e reason]);
} @finally {
    NSLog(@"finally");
}

try/catch error thrown is NSInvalidArgumentException reason -[__NSCFArray length]: unrecognized selector sent to instance 0x68c8e90.
Should I parse the JSON output differently if the output is just 1 array element. Appreciate help

Thanks

  • 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-15T03:22:24+00:00Added an answer on June 15, 2026 at 3:22 am

    Do this,

    id obj = [json objectForKey:@"activitiesList"];
    NSArray* activityListFromSiebel = nil;
    
    if ([obj isKindOfClass:[NSArray class]]) {
        activityListFromSiebel = (NSArray *)obj;
    } else {
        activityListFromSiebel = [NSArray arrayWithObject:obj];
    }
    

    The problem is that when you are trying to use your code, you are assuming that [json objectForKey:@"activitiesList"]; is an array, but actually it is just a dictionary when only a single item is present. Either you can by pass your for loop and convert your dictionary to ObjActivityData object in the else part, or just add this as a quick fix before the for loop which you are using now.

    So your code will look like this,

    NSError* error;
    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
    
    id obj = [json objectForKey:@"activitiesList"];
    NSArray* activityListFromSiebel = nil;
    
    if ([obj isKindOfClass:[NSArray class]]) {
        activityListFromSiebel = (NSArray *)obj;
    } else {
        activityListFromSiebel = [NSArray arrayWithObject:obj];
    }
    
    NSLog(@" Count is %d", [activityListFromSiebel count]);
    for (int i = 0; i < [activityListFromSiebel count]; i++) {
        //if ([activityListFromSiebel count] > 1) {
            NSDictionary* completeActivity = [activityListFromSiebel objectAtIndex:i];
    
            ObjActivityData *dataActivity = [[ObjActivityData alloc] init];
            dataActivity.activityUID      = [completeActivity objectForKey:@"auid"];
            dataActivity.activitytype     = [completeActivity objectForKey:@"type"];
            dataActivity.activityStatus   = [completeActivity objectForKey:@"status"];
            dataActivity.activityOpenedDt = [completeActivity objectForKey:@"createDate"];
            dataActivity.activityDueDt    = @"";
            dataActivity.activityDesc     = [completeActivity objectForKey:@"comments"];
            dataActivity.activityResponse = [completeActivity objectForKey:@"response"];
            [Activities addObject:dataActivity];
            dataActivity = nil;
        //}
    }
    [self.tableView reloadData];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My JSON output currently looks like this: description:MUSIC VIDEO - 7:13\n\nCREDITS\n\nLabel: Black Pain Records\nProduction
I am having this rather long json output in my controller, I wish to
I have a YQL output JSON string at this URL: YQL JSON I found
Why does this output a 0 byte file? <?php $jsonurl = http://do.convertapi.com/Web2Pdf/json/?curl=http://stackoverflow.com/; $json =
How can i convert this JSON array: This is a serialized JSON array 2012-06-18
i have this JSON object: {error:null, result:[{id:1234567890, count:1, recipients: [u3848, u8958, u7477474 ], dateCreated:2012-06-13T09:13:45.989Z
I have a json output array like this { data: [ { name: Ben
I have a json output that looks like this.. { XXXX: { name: Dalvin
I am new to json. I have json output that looks like this [
I'm pulling in a json object, this is the result of a $.parseJSON output.

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.