我正在使用 XML 解析器来获取我的数据。
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentNodeContent = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ( [elementName isEqualToString:@"country"] )
{
x++;
[messages addObject:[NSDictionary dictionaryWithObjectsAndKeys:Id,@"ID",Name,@"NAME",Image,@"IMAGE",nil]];
//**111**
NSLog(@"Data in Message : %@", [messages objectAtIndex:(x-1)]);
[Id setString:@""];
[Name setString:@""];
[Image setString:@""];
}
if ( [elementName isEqualToString:@"id"] )
{
[Id appendString:currentNodeContent];
}
if ( [elementName isEqualToString:@"name"] )
{
[Name appendString:currentNodeContent];
}
if ( [elementName isEqualToString:@"im"] )
{
[Image appendString:currentNodeContent];
}
}
//在 // * 111 *打印消息,但是当我在调用 xml 解析器后执行此操作时,它不会打印:
chatParser = [[NSXMLParser alloc] initWithData:receivedData];
[chatParser setDelegate:self];
[chatParser parse];
NSLog(@"\n\nMessages...\n\n%@", messages); //here there is no data printing
此时它打印为空..
消息。
(
{
ID = "";
IMAGE = "";
NAME = "";
},
{
ID = "";
IMAGE = "";
NAME = "";
},
{
ID = "";
IMAGE = "";
NAME = "";
},
{
ID = "";
IMAGE = "";
NAME = "";
},
{
ID = "";
IMAGE = "";
NAME = "";
},
)
我已经定义了消息属性并对其进行了综合。在viewDidLoad我做了这个
messages=[[NSMutableArray alloc] init];
谢谢你的帮助..