Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Android & xhr Encoding

I'm taking a look at Android.
I have an app that work perfectly with iPhone. The parsing of my UTF-8 XML is ok and the display in a tableView fine.

But with android all french specific caracters are messed up with encoding pb :
http://yfrog.com/0fcapturedcran20100531010p

I do not have the problem when a create a tableView with local data. So i suspect xhr ….

Any ideas ?

I had the problem in webview but adding the META Content-Type with UTF-8 solved the problem.

Thanks.

— asked May 30th 2010 by Stephane Pelamourgues
  • android
  • encoding
  • utf8
1 Comment
  • I also have this problem. I have forced charset to utf-8 in the headers and prefixed the xml with <?xml version="1.0" encoding="utf-8"?>.
    Both did not work.

    I had to URL encode the strings before sending them in xml format within the web service itself to get them properly in android simulator.

    Loic

    — commented July 22nd 2010 by Loic Talbot

4 Answers

  • Can you pastie as snippet of code that points to your URL that we can run through the debugger to see what's happening?

    — answered May 31st 2010 by Jeff Haynie
    permalink
    1 Comment
    • Here is my JS window :
      http://pastie.org/private/kpp6dhupgscm5oaixzx3eq

      What I see in the tableView :
      http://img541.imageshack.us/img541/5505/capturedcran20100531212.png

      A Titanium.API.log gives me the same encoding error:
      [INFO] [122,5007] [content : Contenu éà èç]

      Thanks a lot for your help.

      — commented May 31st 2010 by Stephane Pelamourgues
  • I was having exactly the same problem and I think I found a workaround.

    In KitchenSink (Resources/examples/xhr_utf8.js), the test for UTF-8 passes a UTF-8 value which is echoed back.

    I added an arbitrary argument 'a' with a UTF-8 value:

    xhr.send({"a":"€"});
    

    This appears to trigger correct encoding.

    — answered May 31st 2010 by g w
    permalink
    1 Comment
    • thanks George, but no luck with this.

      I figured out two things (both with UTF-8 encoding):
      When a php webservice has utf8_encode, if i remove it - this works
      When a php webservice has no specific indication, if i add utf8_decode - this works.

      This is really strange.

      — commented May 31st 2010 by Stephane Pelamourgues
  • I had wrongly assumed that adding the UTF-8 parameter had solved the problem.

    I added

    AddDefaultCharset UTF-8
    

    to the apache config which forces the header:

    Content-Type: text/plain; charset=UTF-8
    

    BTW, running

    curl -v -o /dev/null http://yfrog.com/0fcapturedcran20100531010p
    

    shows

    ...
    Content-Type: text/html
    ...
    
    — answered June 2nd 2010 by g w
    permalink
    2 Comments
    • thanks for your answer.
      the yfrog is the link to the hosting for the image of my error.

      My XML is this one : http://polariscorp.free.fr/text.xml
      Curl return : Content-Type: application/xml

      So i set AddDefaultCharset UTF-8 in my apache config with no luck.

      What is weird is that every thing works perfectly on the iPhone Simulator.

      — commented June 2nd 2010 by Stephane Pelamourgues
    • The XML file http://polariscorp.free.fr/text.xml has encoding set to:

      <?xml version="1.0" encoding="iso8859-1"?>
      

      Have you tried changing it to UTF-8

      — commented June 2nd 2010 by g w
  • Are you sure your server reponse content type looks similar to:
    Content-Type: application/json; Charset=utf8

    You can debug it for example with fiddler

    If you don't set Charset=utf8, the default character encoding is taken, which is not UTF8 (it's defined in the apache libs) (Line 446)

    The UTF8 Strings in the request are not required. (android)

    For further info have a look at android source:
    https://github.com/appcelerator/titanium_mobile/blob/1_4_1/android/modules/network/src/ti/modules/titanium/network/TiHTTPClient.java#L446

    — answered December 2nd 2010 by Bernd Baumanns
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.