简体   繁体   English

如何在两个不同的数组中获得响应?

[英]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.

相关问题 如何为两个不同的pickerviews(swift4)调用2个不同的数组 - how to call 2 different arrays for two different pickerviews (swift4) 如何在Swift 3中减去并获得两个数组的差? - how to subtract and get the difference of two arrays in swift 3? 如何在Swift中获取2个数组的不同(非常见)项的列表 - How to get list of different (un-common) items of 2 arrays in Swift 如何比较两个数组以获得相似对象的数量? - How do you compare two arrays to get the count of similar objects? 如何在ios swift 4中多个两个字符串数组并获得总值 - How to Multiple Two String Arrays and get total value in ios swift 4 如何比较两个数组? 并获得不在另一个元素中的元素? - How to compare two arrays? And get the element which are not in the other one? 如何使用swift3在UITableView中的两个不同单元格中显示两个数组 - How to display two arrays in two different cells in UITableView using swift3 如何在两个不同数组的特定索引处合并两个数组值 - How to combine two array values at a particular index from two different arrays 两种UITableViewCell,两种与JSON不同的数组。 如何填充UITableView? - Two kind of UITableViewCell , Two Different Arrays from JSON . How to Populate the UITableView? 如何用来自两个不同对象类型的两个数组的数据填充UITableView? - How can you fill a UITableView with data from two arrays of two different object types?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM