Objective c IOS阵列中断错误

Objective c IOS阵列中断错误,objective-c,arrays,Objective C,Arrays,我调用我的服务器并收到一个带有长字符串的响应,我将其拆分并存储到数组中。我在Android上做得很好,但在xcode中似乎无法理解。这就是我必须为IOS做的事情: 安卓: while (flag) { ProductListArray.add(ProductListOneString.substring(0, ProductListOneString.indexOf('_'))); ProductListOneStr

我调用我的服务器并收到一个带有长字符串的响应,我将其拆分并存储到数组中。我在Android上做得很好,但在xcode中似乎无法理解。这就是我必须为IOS做的事情:

安卓:

while (flag) {
                    ProductListArray.add(ProductListOneString.substring(0, ProductListOneString.indexOf('_')));
                    ProductListOneString = ProductListOneString.substring(ProductListOneString.indexOf('_'));

                    if (ProductListOneString.equals("_")) {
                        flag = false;
                    } else {
                        ProductListOneString = ProductListOneString.substring(1);
                    }
                }


                int index = 2;
                int ArraySize = ProductListArray.size();
                ProductKeycodes = new ArrayList<>();
                while(ArraySize > 0){
                    ProductKeycodes.add(ProductListArray.get(index));
                    index = index + 3;
                    ArraySize = ArraySize - 3;
                }

首先,通过在“\u1”处打断,将字符串拆分为一个子字符串数组,然后测试第一个这样的子字符串是否为“\u1”,因为分隔符不是子字符串的一部分

您的Android代码正在迭代,以实现
组件通过字符串分离:
在一次调用中为您完成的功能。您可以完全替换
while
,并将
组件通过字符串分离的结果添加到
产品列表数组中

顺便说一句,Objective-C中以小写字母开头的变量-请注意,当您使用大写字母时,语法着色是如何错误的

NSString *ProductListOneString = response;
    NSMutableArray *ProductListArray;


    bool flag = true;

    while (flag) {

        //[ProductListArray addObject: [ProductListOneString substringFromIndex:0 ProductListOneString: index(@"_", 0)]];


        [ProductListArray addObject: [[ProductListOneString componentsSeparatedByString:@"_"] objectAtIndex:0]];
        ProductListOneString = [[ProductListOneString componentsSeparatedByString:@"_"] objectAtIndex:0];

        if ([ProductListOneString isEqualToString: @"_"]) {
            flag = false;
        } else {
            ProductListOneString = [ProductListOneString substringFromIndex: 1];//I get a *signal sigabrt* error here
        }
    }



    NSInteger index = 2;
    int ArraySize = [ProductListArray count];

    NSMutableArray *ProductKeycodes;

    while(ArraySize > 0){

        [ProductKeycodes addObject: [ProductListArray objectAtIndex: index]];

        index = index + 3;
        ArraySize = ArraySize - 3;
    }