[英]how to get response in two different arrays?
I am doing a weather report app. 我正在做一个天气预报应用程序。 So i am going to get the yahoo services API.
因此,我将获得yahoo服务API。 This following code is
以下代码是
<yweather:forecast day="Thu" date="20 Dec 2012" low="70" high="89" text="Partly Cloudy" code="30"/>
<yweather:forecast day="Fri" date="21 Dec 2012" low="71" high="90" text="Partly Cloudy" code="30"/>
I need to get these two tags attribute values in two different arrays... 我需要在两个不同的数组中获得这两个标签的属性值...
first one is one array and the second one is in another array 第一个是一个数组,第二个是另一个数组
how can i do this help me thanks in advance 我该如何帮助我预先感谢
Try this: 尝试这个:
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:@"forecast"])
{
if(firstarray.count == 0)
{
firstarray = [attributeDict allValues];
}
else
{
secondarray = [attributeDict allValues]
}
}
}
You could use the event-driven parser NSXMLParser . 您可以使用事件驱动的解析器NSXMLParser 。
And, here's how to handle elements while parsing. 并且,这是解析时如何处理元素的方法 。 The
attributes
dictionary parameter of the delegate method parser:didStartElement:namespaceURI:qualifiedName:attributes:
will give you the element attributes which you can process as per your needs ie. 委托方法
parser:didStartElement:namespaceURI:qualifiedName:attributes:
的attributes
dictionary参数将为您提供元素属性,您可以根据需要进行处理。 add to an array. 添加到数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.