gpt4 book ai didi

ios - NSXMLParser 读取 xml 文件时出现重复数据

转载 作者:行者123 更新时间:2023-11-29 05:37:55 30 4
gpt4 key购买 nike

我有这样的 xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<background>assets/_image.png</background>
<items>
<item type='test1' position='6' x='123' y='456'>
my_way
</item>
<item type='test2' position='8' x='456' y='123'>
another_way
</item>

........................

我使用 NSXMLParser 阅读它:

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([self.currentTag isEqualToString:@"item"]) {
[self addItemForAttributes:self.currentAttributes withValue:string];

NSLog(@"%@", self.items.lastObject.type);
NSLog(@"%@", self.items.lastObject.position);
NSLog(@"%@", NSStringFromCGPoint(self.items.lastObject.coordinate));
NSLog(@"%@", self.items.lastObject.value);
}
}

我将项目写入项目数组中。但是当我在控制台中读取它时,有些项目看起来是重复的。

2019-07-02 17:25:53.326939+0300 Game[1280:235820] test1
2019-07-02 17:25:53.327083+0300 Game[1280:235820] 6
2019-07-02 17:25:53.327445+0300 Game[1280:235820] {123, 456}
2019-07-02 17:25:53.327671+0300 Game[1280:235820] my_way
2019-07-02 17:25:53.327946+0300 Game[1280:235820] test1
2019-07-02 17:25:53.328021+0300 Game[1280:235820] 6
2019-07-02 17:25:53.328301+0300 Game[1280:235820] {123, 456}
2019-07-02 17:25:53.328348+0300 Game[1280:235820]
2019-07-02 17:25:53.328991+0300 Game[1280:235820] test1
2019-07-02 17:25:53.329112+0300 Game[1280:235820] 6

如何解决?

最佳答案

委托(delegate)方法(找到的字符)调用了几次,我为它做了条件(过滤空字符串),所以它解决了我的问题。

关于ios - NSXMLParser 读取 xml 文件时出现重复数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56854921/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com