问题
my data coming in this format
(
(
Male,
Female
),
(
First,
Second,
Third
)
)
and I want in this format
(
Male,
Female
),
(
First,
Second,
Third
)
how to remove extra bracket from array
if ([[allObject objectForKey:@"Fid"] isKindOfClass:[NSArray class]])
{
NSArray *arr = (NSArray *)[allObject objectForKey:@"Fid"];
for (int i =0; i<arr.count; i++) {
if ([[arr valueForKey:@"Values"]objectAtIndex:i] != (id)[NSNull null] ) {
NSMutableArray *fetchArray = [[NSMutableArray alloc]init];
[fetchArray addObjectsFromArray:[[arr valueForKey:@"Values"] objectAtIndex:i]];
[fetchValue addObject:fetchArray];
}
}
}
I have tried addObject
and addObjectFromArray
but in addObjectFromArray
output comes in (male,female,first,second,third)
and i want like (male,female),(first,second,third)
回答1:
This line [fetchValue addObject:fetchArray];
is the problem. You need use =
and not addObject
.
In your fetchValue
mutableArray you are adding other mutableArray fetchArray
, finally you get array of arrays. Only use =
回答2:
Objective-C doesn't care about you want. In this case, you can't get what you want.
You can have an array containing two arrays. That's what you got. You can't have nothing containing two arrays. It just doesn't make sense.
And note that your data isn't coming in this format. What you posted is the output of NSLog, it's not your data.
来源:https://stackoverflow.com/questions/35771327/objective-c-addobject-to-store-array-return-extra-bracket-for-me-how-to-remove