gpt4 book ai didi

iphone - 无法解析以下 XML?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:21:37 25 4
gpt4 key购买 nike

我有 img id="#" 的连续标签,其中 # 从 1 到 9 不等。

标签的描述由 float 值组成。

当我使用标准的 NSXML 解析器时,我没有得到所有的值。

我的 XML 供引用:

<img id="1">-0.0111328,-0.0635608,0.152549,0.11211,-0.0250431,

-0.0370875,0.0862391,0.0970791,-0.0195908,

-0.00892297,0.0791795,0.0554013,0.00362028,0.0138572,0.0432729,

0.0253036,-0.0770325,0.14065,0.118424,0.1787,

0.0734354,0.160883,0.101831,0.237038,0.0681151,0.178331,

0.106532,0.224731,0.133766,0.222096,0.165214,0.240752,

-0.0280366,0.106239,0.052094,0.110642,

</img>

我将如何解析上述 XML?

请帮帮我。

谢谢

最佳答案

这是因为parser:foundCharacters:不会一次传送所有字符。您需要连接在 parser:didStartElement:namespaceURI:qualifiedName:attributes: 的回调之间获得的所有字符串和 parser:didEndElement:namespaceURI:qualifiedName:你得到的<img>标签。

在下面的代码中,buf是一个 NSMutableString你的解析器代理的 ivar。

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
if ([qualifiedName isEqualToString:@"img"]) {
buf = [NSMutableString string];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([qualifiedName isEqualToString:@"img"]) {
buf = [buf stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(@"Got %@", buf);
}
}

- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
[buf appendString:string];
}

关于iphone - 无法解析以下 XML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10974474/

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