shubham mishra
shubham mishra

Reputation: 991

How to fetch each value from Array of strings inside an Array

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;
    }

Upvotes: 0

Views: 81

Answers (2)

Jigar Tarsariya
Jigar Tarsariya

Reputation: 3237

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.

Upvotes: 1

Nirav D
Nirav D

Reputation: 72410

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

Upvotes: 2

Related Questions