Decoding HttpEntity into android string - encoding issue

Poutrathor

I know that should be basics but i had no formation :( and I don't understand it, everywhere it seems obvious to people. I get that one side encode data with his set and android is probably expecting another one, but what can I do to translate?

My app perform a get request on google maps api to retrieve an address from a Lat/lng. But I failed to decode properly the result as a French è is displayed as è

I have not enough xp in Java to understand what to do. It is linked with UTF-8, right?

What should I do?

            response = client.execute(httpGet);
            HttpEntity entity = response.getEntity();
            InputStream stream = entity.getContent();
            int b;
            while ((b = stream.read()) != -1) {
                stringBuilder.append((char) b);
            }
            JSONObject jsonObject = new JSONObject();
            jsonObject = new JSONObject(stringBuilder.toString());
            retList = new ArrayList<Address>();
            if("OK".equalsIgnoreCase(jsonObject.getString("status"))){
                JSONArray results = jsonObject.getJSONArray("results");
                for (int i=0;i<results.length();i++ ) {
                    JSONObject result = results.getJSONObject(i);
                    String indiStr = result.getString("formatted_address");
                    Address addr = new Address(Locale.ITALY);
                    addr.setAddressLine(0, indiStr);
                    Dbg.d(TAG, "adresse :"+addr.toString());
                    retList.add(addr);
                }
            }

Thanks for help !

Lalit Poptani

Try using UTF-8,

instead of using InputStream try something like,

String responseBody = EntityUtils.toString(response.getEntity(), HTTP.UTF_8);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Decoding HttpEntity into android string - encoding issue

From Dev

Encoding and Decoding string

From Dev

Encoding and Decoding string

From Dev

Encoding and Decoding GameState Class Issue

From Dev

Understanding String encoding/decoding Java

From Dev

decoding and encoding Hebrew string in Python

From Dev

Some Decoding Issue With String in Python

From Dev

String encoding issue in Ruby

From Dev

Java encoding/decoding a String to/from a long

From Dev

URL-encoding and -decoding a string in Python

From Dev

Android Wear Message API Encoding and Decoding Byte[]

From Dev

Decoding string Char.Parse issue

From Dev

JS String concatenate encoding issue

From Dev

Encoding issue with string stored in database

From Dev

JS String concatenate encoding issue

From Dev

StringEntity/string to HttpEntity

From Dev

Why is there a newline on the end of my string when I finish decoding and encoding it?

From Dev

OutOfMemoryError while decoding and encoding Base64 String into Bitmap

From Dev

Is there any separate Java api for encoding the string and as well as decoding

From Dev

Encoding/decoding arbitrary binary data to string in swift/objective-c

From Dev

Android Base64 Encoding and Apache codec decoding

From Dev

Decoding URL encoding (percent encoding)

From Dev

Encoding and decoding custom objects

From Dev

Encoding for fastest decoding with ffmpeg

From Dev

Python encoding/decoding problems

From Dev

Basic Unicode encoding/decoding

From Dev

Encoding and decoding in postgresql

From Dev

TLV encoding and Decoding

From Dev

QMessageBox - url encoding/decoding