0

我见过可能谈论这个的话题,但没有一个对我有用。我正在尝试解析 GEORSS,并使用以下格式给我坐标:

<georss:point>4613618.31000115 676474.87007986</georss:point>

因此,我尝试将其拆分为 NSArray,然后将它们分配给相应的 XML 键,但它总是因该错误而崩溃:

2013-04-02 12:33:11.234 GeoRss1[2125:c07] * 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“* -[__NSArrayM objectAtIndex:]:索引 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 called throwing an exception (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;
...

谢谢大家的进步,你们已经在其他主题上帮助了我一些回复!

4

1 回答 1

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

它对我来说非常有效。我认为问题是您没有在字符串中获得正确的数据。

于 2013-04-02T10:54:05.097 回答