XML Parse \和特殊字符问题

时间:2014-07-15 17:23:03

标签: ios objective-c xml-parsing

当我尝试解析肥皂结果时。我得到了不想要的结果。

我得到了这个结果

最终结果:[{“UserID”:9,“EMail”:“1”,“UserName”:“1”,“密码”:“c4ca4238a0b923820dcc509a6f75849b”,“FullName”:“1”,“性别” : “KADIN”}]

并解析它。

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

    NSLog(@"DONE. Received Bytes:%lu",(unsigned long)[responseData length]);

    NSString *theXml = [[NSString alloc] initWithBytes:[responseData mutableBytes] length:[responseData length] encoding:NSUTF8StringEncoding];

    NSLog(@"The final result :%@",theXml);

    if (xmlParser) {
        xmlParser = [[NSXMLParser alloc] initWithData: responseData];
        [xmlParser setDelegate:self];
        [xmlParser setShouldResolveExternalEntities:YES];
        [xmlParser parse];
    }
}

-(void) parser:(NSXMLParser *) parser didStartElement:(NSString *) elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *) qName attributes:(NSDictionary *)attributeDict {

    if ([elementName isEqualToString:@"GetUserResult"]) {

        soapResults = [[NSMutableString alloc] init];
        elementFound = YES;
    }
}

-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string
{
    if (elementFound)
    {
        [soapResults appendString: string];
    }
}

-(void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
 namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"GetUserResult"])
    {
        NSArray *userInfo = [[NSArray alloc] initWithObjects:soapResults, nil];
        NSLog(@"%@", soapResults);
        NSLog(@"%@", userInfo);
    }
}

在第一个nslog中就是我想要的。

NSLOG 1: [{ “用户ID”:9, “电子邮件”: “1”, “用户名”: “1”, “密码”: “c4ca4238a0b923820dcc509a6f75849b”, “全名”: “1”, “性别”: “KADIN”}] < / p>

但是当我把肥皂结果放入NSArray时,我得到了这个 NSLOG 2: [{\ “用户ID \”:9,\ “邮件\”:\ “1 \” \ “用户名\”:\ “1 \” \ “密码\”:\ “c4ca4238a0b923820dcc509a6f75849b \”,\“全名\ “:\” 1 \” \ “性别\”:\ “喀\ U0131n \”}]

我该如何解决?感谢。

0 个答案:

没有答案