Messed up character encoding with Android + GAE Cloud Endpoints

后端 未结 1 1757
无人共我
无人共我 2020-12-18 05:41

I made web app using GAE\'s Cloud Endpoints. App has only backend part. App calls Google Places API and parses JSON responses, creating objects which returns to client. Clie

1条回答
  •  青春惊慌失措
    2020-12-18 06:13

    SOLVED IT!!!!

    I think that this is Google's bug evenly as mine. I assumed that response will be encoded in UTF-8, so I just used:

    URL url = new URL(PLACE_AC_API + encodedInput + PLACE_AC_API_OPTIONS);
    connection = (HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);
    BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    

    With explicitly adding charset argument everything worked out:

    BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charset.forName("UTF-8")));
    

    But Google definitely need to see why this behaves differently in local and deployed.

    All the best to everyone, thanks for interesting and effort!

    0 讨论(0)
提交回复
热议问题