I am developing an android app that displays text in 3 languages - english, kurdish and arabic. The data is fetched from the server using a php script which encodes the data as json.
The above is the script that fetches data. The mysql server that contains the data uses utf8 encoding. I have also modified the code in java to accept utf8 encoded strings-
What could be wrong in the whole process? Thanks in advance.
Code:
$subcat_id = mysql_real_escape_string(intval($_GET["id"]));
$query = mysql_query("select * from subcategory where category_id = $subcat_id")or die(mysql_error());
while($row = mysql_fetch_assoc($query))
$output[]=$row;
print(json_encode($output));
Code:
public static String executeHttpGet(String url) throws Exception {
BufferedReader in = null;
try {
HttpClient client = getHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI(url));
HttpResponse response = client.execute(request);
// in = new BufferedReader(new InputStreamReader(response.getEntity()
// .getContent()));
in = new BufferedReader(new InputStreamReader(response.getEntity()
.getContent(), "UTF-8"));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String result = sb.toString();
return result;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
Log.e("log_tag", "Error converting result " + e.toString());
e.printStackTrace();
}
}
}
}