我正在尝试解析一个看起来像这样的 XML。
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<WM_Login_MobileAppResponse xmlns="A.MobileAppService">
<WM_Login_MobileAppResult>
<Login xmlns="">
<Customer_Type>5</Customer_Type>
<Token>token</Token>
</Login>
</WM_Login_MobileAppResult>
</WM_Login_MobileAppResponse>
</soap:Body>
我试过 NSXMLParsesr 来解析文档。我正在使用的代码是:
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:@"WM_Login_MobileAppResult"]) {
_resultDict = [[NSMutableDictionary alloc] init];
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
[_resultDict setObject:_currentString forKey:elementName];
if ([elementName isEqualToString:@"WM_Login_MobileAppResult"]) {
[_array addObject:_resultDict];
_resultDict = nil;
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
_currentString = [[NSString alloc] initWithString:string];
}
这是我得到的结果:
(
{
"Customer_Type" = 4;
Login = "token";
Token = "token";
"WM_Login_MobileAppResult" = "token";
}
)
有人可以帮我得到正确的回应吗?