-1

I have a problem I can't deal with.

In my application, I get datas from my Web Service in JSON. It's UTF8-encoded and when I fill an UITableView everything is ok (NSLog return accents like : "\u00e9" but my UITableView shows it like : "é").

But when I set the same data in my detailTextLabel, it doesn't convert "\u00e9" to "é" ...

Tried some tricks with encoding, but nothing convincing.

Parsing methods :

- (NSDictionary*)fetchedData:(NSData *)responseData {

NSError* error;

self.json = [NSJSONSerialization
                      JSONObjectWithData:responseData

                      options:kNilOptions
                      error:&error];

return self.json;
}



-(void)executeParsingWithUrl:(NSURL*)anUrl{
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:anUrl];
NSString *authStr = [NSString stringWithFormat:@"%@:%@",[[NSUserDefaults standardUserDefaults] stringForKey:@"username_ws"], [[NSUserDefaults standardUserDefaults] stringForKey:@"password_ws"]];
NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];
NSString *authValue = [NSString stringWithFormat:@"Basic %@", [Base64 encode:authData]];
[urlRequest setValue:authValue forHTTPHeaderField:@"Authorization"];
NSError *requestError = NULL;
NSHTTPURLResponse *response = NULL;

NSData *responseData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&requestError];

[self performSelectorOnMainThread:@selector(fetchedData:)
                       withObject:responseData waitUntilDone:YES];
}

Recuperation :

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        JsonParsing *getJson = [[JsonParsing alloc] init];
        [getJson executeParsingWithUrl: leUrl];

        self.duration = [NSString stringWithFormat:@"%@",[[getJson.json objectForKey:@"objects"]valueForKey:@"libel"]];
    });

Thanks in advance !

Ritooon
  • 155
  • 12
  • It should work. As a test I did 'cell.detailTextLabel.text = @"\u00e9";' and it showed è – John Mar 26 '14 at 15:28
  • 2
    The display of text in a UITableView _is_ a UILabel, just like `detailTextLabel`. So if you are getting different results in the display, it is because you are processing the data differently. However, you have chosen not to reveal any of your code, so it's impossible to say how. – matt Mar 26 '14 at 15:28
  • I decided to not reveal code beacause I thought it was something general, not something in my code if it was good for the cell textlabel .. – Ritooon Mar 26 '14 at 15:49
  • @Ritooon there is pretty much no reason for not showing your code. Countless times I have run into issues where people think its the same thing. Never assume anything. If you have a question, show us what your talking about – Simon McLoughlin Mar 26 '14 at 15:51
  • Yep I understand what you're saying. Just thought there was some trick ... But I posted a piece of my code. Sorry about didn't done it before – Ritooon Mar 26 '14 at 15:55
  • It seems now there's my code, no one want to help me :( – Ritooon Mar 26 '14 at 16:24
  • Little up ... Someone to help me ? – Ritooon Apr 03 '14 at 14:38

1 Answers1

2

I managed it thanks to other people. I my cell.detailTextLabel I used this :

cell.detailTextLabel.text = [NSString stringWithCString:[myText cStringUsingEncoding:NSUTF8StringEncoding] encoding:NSNonLossyASCIIStringEncoding];
Ritooon
  • 155
  • 12