0
我試圖分裂一個字符串,並將其分成不同的,但我得到了以下錯誤:的Xcode 4 NSRangeException錯誤分割字符串後
* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
代碼:
NSLog(@"%@", strResult);
NSArray* LocInfo = [strResult componentsSeparatedByString: @"|"];
NSString* Response1 = [LocInfo objectAtIndex: 0];
NSString* Response2 = [LocInfo objectAtIndex: 1];
NSString* Response3 = [LocInfo objectAtIndex: 2];
任何想法?謝謝!
是的,我有這樣的正在從Web服務返回的,有時它沒有回傳第三元素的字符串。謝謝! – NCoder 2013-04-10 10:02:07
所以不需要硬編碼索引:3,檢查它的計數是否只有3,然後訪問該元素。 – 2013-04-10 10:03:18
會做!在我允許的情況下,我會接受你的回答作爲答案。 – NCoder 2013-04-10 10:03:59