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