ios - 如何从数组中的字符串数组中获取每个值

标签 ios objective-c xcode nsstring nsarray

我在名为 officeList 的数组中有一个数组,格式如下:-

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

问题是我通过将 JSON 文件转换为数组得到了这个数组,结果我在数组中得到了这个字符串数组。我想要的是一个一个地获取每个值,例如:“prospect”、“propose”等。

我正在使用以下代码获取数据:

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

最佳答案

你试过吗

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

此处 jsonArr 是您从响应中获取的数组。现在使用 arr 访问您想要的每个对象。

希望对你有帮助

关于ios - 如何从数组中的字符串数组中获取每个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37944020/

相关文章:

objective-c - 如果@protected 是默认值,为什么这个ivar 需要@protected?

objective-c - stringWithUTF8String : do and how it works 是什么

ios - Kinvey Swift 3 KCSCus​​tomEndpoints

iphone - iOS4 位置跟踪在后台和时间间隔

android - 如何阻止用户访问锁定屏幕中的状态栏和导航栏?

ios - 更改约束目标类

objective-c - 从 float 中获取小数部分

ios - 将 #s 数组存储到 NSUserDefaults,为与数组中的 # 匹配的每个单元格行添加复选标记

iphone - 优雅的方式来实现iOS应用程序内升级(功能解锁)

ios - 由于未捕获的异常 'NSRangeException' 而终止应用程序,原因 : '*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'