0

I'm calling an API and receiving a response in Spanish. In the Browser it looks OK, but when I call it in the app, it shows weird characters.

For example, in the browser I see Automóvil, but in the app I see Automóvil.

I'm using RestKit:

[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObjects:@"text/html",@"charset=UTF-8", nil]];

RKObjectManager *manager = [RKObjectManager managerWithBaseURL:baseURL];

manager.requestSerializationMIMEType = RKMIMETypeJSON;
[manager.HTTPClient setDefaultHeader:@"Content-Type" value:@"application/json"];
[manager.HTTPClient setDefaultHeader:@"Accept" value:@"application/json"];
[manager.HTTPClient setDefaultHeader:@"Accept-Encoding" value:@"gzip, deflate"];`
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
Ahsan
  • 827
  • 6
  • 10
  • Those are [HTML character references](http://en.wikipedia.org/wiki/Character_encodings_in_HTML). There's bound to be a decoding method for that on your platform. – Pekka Apr 06 '15 at 23:20
  • Related: http://stackoverflow.com/questions/1067652/converting-amp-to-in-objective-c – Pekka Apr 06 '15 at 23:21
  • How are you testing it in the app? – Wain Apr 07 '15 at 06:45
  • [[RKObjectManager sharedManager].HTTPClient getPath:@"api.php" parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) { } failure:^(AFHTTPRequestOperation *operation, NSError *error) { }]; } – Ahsan Apr 07 '15 at 11:19
  • I'm calling it in above way – Ahsan Apr 07 '15 at 11:19
  • I don't want to HTML encode and decode every time, I'm sure there will be a way out to get response in proper form. – Ahsan Apr 07 '15 at 11:20

1 Answers1

0

The information you're receiving is encoded with HTML entities (also called "character entity references"). For example, ó represents ó because of the acute accent over the o.

Ideally, you'd have an API that would just send you everything in UTF-8, but if that's not possible, you'll need to decode the text yourself. This Stack Overflow question provides a number of solutions.

Community
  • 1
  • 1
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
  • If you only need to support iOS 7 and above, I would try [this approach first](http://stackoverflow.com/a/21901056/1445366). – Aaron Brager Apr 06 '15 at 23:23