0

I have an array inside an array named as officeList in the following format :-

(
        (
        Prospect,
        Propose
    ),
        (
        Open,
        Fund,
        Propose
    ),
        (
        Settle,
        Review
    )
)

Problem is I got this array by converting the JSON file into an array and as a result of that I got this array of string inside an array. What I want is to fetch each value one by one like : "prospect", "propose", etc.

I am using following code to fetch data :

for (int i = 0;i<[_officelist count];i++)
{
    id val=[officeSize objectAtIndex:i];
    CGFloat val1=[val floatValue];
    UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 20,val1,15)];

    newLabel.text=[NSString stringWithFormat:@"%@",_officelist[i]];

    newLabel.textAlignment = NSTextAlignmentCenter;


    [self.roadmapCollectionView addSubview:newLabel];

    x=x+val1;
    }
3
  • You need another loop to loop over each element of _officelist[i] ? Commented Jun 21, 2016 at 12:13
  • your code having bug, officelist and officeSize count may be mist match so you can not write id val=[officeSize objectAtIndex:i]; directly Commented Jun 21, 2016 at 12:16
  • if i am not using id type to convert NSArray to CGFloat, then what to use ? Commented Jun 21, 2016 at 17:52

2 Answers 2

2

Have you try this

NSMutableArray *arr = [[NSMutableArray alloc] init];
for (NSArray *objArr in jsonArr) {
    for (NSString *str in ObjArr) {
        [arr addObject:str];
    }
} 

Here jsonArr is the array that you getting from response. Now use arr to access every object that you want.

Hope this will help you

Sign up to request clarification or add additional context in comments.

Comments

1

Apply below code,

for (int i = 0; i < [_officelist count]; i++)
{
    NSArray *valList=[_officelist objectAtIndex:i];

    CGFloat val1 = [valList floatValue]; // Your Float val


    for (int j = 0; j < [valList count]; j++)
    {
         UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 20,val1,15)];

         newLabel.text = [NSString stringWithFormat:@"%@",valList[j]];

         newLabel.textAlignment = NSTextAlignmentCenter;

         [self.roadmapCollectionView addSubview:newLabel];
    }

    x=x+val1;
}

Hope this helps you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.