2016-08-12 7 views
-1

私は自分のサーバーに電話をかけ、長い文字列の応答を受け取り、分割して配列に格納します。私はAndroid上でこれを完全に行いましたが、xcodeでそれを理解できないようです。これは私がIOSのために何をすべきかです: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; 
       } 

私はXcodeで、これまで持っているもの:

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

答えて

1

あなたが最初でサブストリングの配列に文字列を破ります"_"を壊してから、最初のそのような部分文字列が "_"であるかどうかを調べる。これは、区切り文字が部分文字列の一部ではないため不可能である。

あなたのAndroidコードは、componentsSeparatedByString:を1回の呼び出しで処理するために反復処理されています。 whileを完全に置き換えて、にcomponentsSeparatedByString:の結果を追加することができます。

Objective-CでBTWの開始変数に小文字を使用すると、大文字を使用したときの構文の色付けがどう違うのかを確認できます。

HTH

関連する問題