I use an XML parser to retrieve an xml from server.
我使用XML解析器从服务器检索XML。
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.url);
it displays the correct URL.
它显示正确的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.
这一点也不正确:我得到的不是政变,而是政变。请告诉我如何在目录中找到正确的电子字符链接。
3 个解决方案
#1
1
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
检查这个NSLog错误编码的问题。UTF8字符也有类似的问题
#2
2
Make sure that your url property is a string in the array.
确保您的url属性是数组中的一个字符串。
@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.
NSString不改变特殊字符,应该输出与输入相同的内容。下面假定您已经将字符串添加到数组中。
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]);
#3
0
Get the UTF8 string value and use it
获取UTF8字符串值并使用它。
[currentCatalogue.url UTF8String];
#1
1
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
检查这个NSLog错误编码的问题。UTF8字符也有类似的问题
#2
2
Make sure that your url property is a string in the array.
确保您的url属性是数组中的一个字符串。
@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.
NSString不改变特殊字符,应该输出与输入相同的内容。下面假定您已经将字符串添加到数组中。
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]);
#3
0
Get the UTF8 string value and use it
获取UTF8字符串值并使用它。
[currentCatalogue.url UTF8String];