I have a couple of string that aren't converting properly. The issue that I had was that all my strings had weird characters on it (They are in spanish with the top accent) and I was able to convert them with the following code:
Connection to DB: After is connected I proceed to get the information from the DB as follows (it comes with json format) DB information shows as Perú:
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
//BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
result = sb.toString();
//is.close();
Log.i("Tag:", result);
}
retrieve JSON list:
try{
jArray = new JSONArray(welcome.result);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
Log.i("log_tag", "title:" + json_data.getString("title"));
try {
country = new String(json_data.getString("country").getBytes("ISO-8859-1"), "UTF-8");
}
catch (UnsupportedEncodingException e){
}
However I grabbed another string in spanish and it reverted back but the other strings still show up properly. The current string looks like this PER�?º Any ideas? Im guessing is using a different encoding. The database where I'm pulling them from uses utf8_general_ci. Thank you in advance!
json_datais aStringretrieved from the database usinggetString()on aResultSet, and you're gettingPER�?º, then whoever inserted that data messed up.