我看过可能讨论过的主题,但没有一个对我有用。我试图解析GEORSS,坐标给我以下格式:
<georss:point>4613618.31000115 676474.87007986</georss:point>
所以我试图将它拆分为NSArray,然后将它们分配给相应的XML密钥,但它总是因为该错误而崩溃:
2013-04-02 12:33:11.234 GeoRss1 [2125:c07] *由于未捕获的异常'NSRangeException'而终止应用程序,原因:'* - [__ NSArrayM objectAtIndex:]:index 1超出界限[0 .. 0]' * 第一次抛出调用堆栈:
(0x1959012 0x1275e7e 0x18fb0b4 0x19d23a8 0x3f48 0xd55a37 0x1c96600 0x1ca1a2b 0x1ca0f07 0xd53e02 0x34b8 0xd7b589 0xd79652 0xd7a89a 0xd7960d 0xd79785 0xcc6a68 0x14a1911 0x14a0bb3 0x14decda 0x18fb8fd 0x14df35c 0x14df2d5 0x13c9250 0x18dcf3f 0x18dc96f 0x18ff734 0x18fef44 0x18fee1b 0x18b37e3 0x18b3668 0x1b9ffc 0x1ddd 0x1d05) libc ++ abi.dylib:terminate调用抛出异常 (lldb)
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
}else if([elemAct isEqualToString:@"georss:point"]){
componentes = [[string componentsSeparatedByString:@" "] mutableCopy];
if ( componentes != nil){
[xmlLat appendString:componentes[0]];
[xmlLon appendString:componentes[1]];
}
...
...
在该文件的标题中,我已正确声明了两个变量并合成它们:
...
@property (strong) NSMutableString *xmlLat;
@property (strong) NSMutableString *xmlLon;
...
感谢大家的高级,你已经帮助我在其他主题中做了一些回应!
答案 0 :(得分:1)
我尝试了以下代码:
NSString *abc = @"4613618.31000115 676474.87007986";
NSArray *componentes = [[abc componentsSeparatedByString:@" "] mutableCopy];
NSLog(@"componentes : %@",componentes);
NSMutableString *xmlLat = [[NSMutableString alloc]initWithString:@""];
NSMutableString *xmlLon = [[NSMutableString alloc]initWithString:@""];
[xmlLat appendString:componentes[0]];
[xmlLon appendString:componentes[1]];
NSLog(@"xmlLat : %@",xmlLat);
NSLog(@"xmlLon : %@",xmlLon);
它对我来说很完美。我解决的问题是你没有在你的字符串中获得正确的数据。