我很长时间难以解析谷歌天气API。我使用NSXML解析器。但没有得到解决方案。我想要获取价值城市,温度,湿度,即将来临的日子。
感谢
湿的api响应是here
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
//if the element name is item then only i am assigning memory to the NSObject subclass
if ([elementName isEqualToString:@""])
{
XMLStringFileObject = [[XMLStringFile alloc]init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
//what ever data i am getting from the node i am appending it to the nodecontent variable after i trim that data for white space or new line character
[nodecontent appendString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
//i am saving the data inside the properties of the XMLStringFileObject from the nodecontent variable
if ([elementName isEqualToString:@"forecast_information"])
{
cityLabel.text =
}
else if ([elementName isEqualToString:@"current_condition"])
{
tempratureLabel.text=
humidityLabel.text=
}
//finally in the end when the item tag is encountered i am adding the data inside the mutable array
if([elementName isEqualToString:@""])
{
}
//release the data from the mutable string variable
[nodecontent release];
//reallocate the memory to get the new data from the xml file
nodecontent = [[NSMutableString alloc]init];
}