开发者

Can't decode UTF8 characters from NSXMLParser

I use an XML parser to retrieve an xml from server.

And I have the following two things:

NSMutableArray *catalogueList;
Catalogue *currentCatalogue;

Catalogue looks like this:

#import "Catalogue.h"

@implementation Catalogue

@synthesize id_model;
@synthesize name;
@synthesize url;

@end

And this piece of code also:

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{    
 if ([elementName isEqualToString:@"catalogue"]) 
{       
    // Add currentCatalogue to array
    [catalogueList addObject: currentCatalogue.url];
}

This works great, but there is a little problem. When I do this:

 NSLog(@"Valoare url %@", currentCatalogue.开发者_StackOverflow中文版url);

it displays the correct URL.

But when I do this:

 NSLog(@"Valoare url %@", catalogueList);

the output is "link".

which is not correct at all: instead of Coupé I get Coup\U00e9. Please tell me how to obtain in catalogueList the correct link with the é character.


Make sure that your url property is a string in the array.

@interface Catalogue : NSObject{

NSString *myURL;

}

NSString doesn't alter special characters, and should output the exact same thing that went in. The following Assumes you already added the string to the array.

NSLog(@"My URL: %@", [currentCatalogue objectAtIndex:0]);

Ouput: My URL: http://host_server/uploads/modeles_pdf/41_TTRS_Coupé_TTRS_Roadster_Tarifs_20110428.pdf

Also, Try doing this to see if you get the same error...

NSString *temp = currentCatalogue.url;
//Check the string
NSLog(@"NSString temp: %@", temp);

//Add it to the array
[catalogueList addObject:temp];

//Assuming object is at index 0, check the object in the array
NSLog(@"My URL: %@", [catalogueList objectAtIndex:0]);


You are printing an array instead of the object. Try this:

NSLog(@"catalogueList url %@", [catalogueList objectAtIndex:0]);

Check out this SOF question NSLog incorrect encoding . Similar problems with UTF8 characters


Get the UTF8 string value and use it

[currentCatalogue.url UTF8String];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜