如何在两个不同的阵列中获得响应?

时间:2022-07-19 12:12:54

I am doing a weather report app. So i am going to get the yahoo services API. This following code is

我正在做一个天气预报应用程序。所以我将获得雅虎服务API。以下代码是

<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

我怎么能这样帮助我提前谢谢

2 个解决方案

#1


0  

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]
        }
    }
}

#2


0  

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. add to an array.

而且,这是解析时如何处理元素。委托方法解析器的attributes字典参数:didStartElement:namespaceURI:qualifiedName:attributes:将为您提供可根据需要处理的元素属性,即。添加到数组。

#1


0  

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]
        }
    }
}

#2


0  

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. add to an array.

而且,这是解析时如何处理元素。委托方法解析器的attributes字典参数:didStartElement:namespaceURI:qualifiedName:attributes:将为您提供可根据需要处理的元素属性,即。添加到数组。