0
Android 마녀의 애플리케이션에 아랍어 텍스트를 사용하는 editText가 있습니다. 다음이 아랍어 텍스트를 기반으로 PHP를 통해 MySQL에서 쿼리를 만듭니다. 문제는 내가 editText에서 아랍어 텍스트를 검색 할 때 MySQL 쿼리가 null을 반환하지만 아랍어 텍스트를 프로그램에서 수동으로 작성할 때 (editText에서 retieving이 아닌 경우) 완벽하고 신이 작동한다는 것입니다. 어떤 사람이 나를 도울 수있는 문제는 무엇입니까? 감사합니다. .Android에서 editText에서 아랍어 텍스트 가져 오기
//Getting the synset from the user to look for
EditText SynsetEditText = (EditText) findViewById(R.id.synsetEditText);
String synsetString = SynsetEditText.getText().toString();
//Removing white space from the beginning and end of the string
synsetString=synsetString.trim();
//synsetString="قط"; if i write here the Arabic word manually the query works fine
myIntent = new Intent(MainActivity.this,AWNActivity.class);
myIntent.putExtra("synset", synsetString);
startActivity(myIntent);
이 AWNActivity.java에 있습니다 :
String url="http://"+localHost+"/smd/connectA.php";
JSONasyncTask asynctask=new JSONasyncTask();
asynctask.execute(url);
private class JSONasyncTask extends AsyncTask<String, Void,JSONArray>
{
@Override
protected JSONArray doInBackground(String... urls)
{
Connect connect=new Connect();
JSONArray jsonArray=connect.ConnectToRESTful(urls[0],synsetString);
return jsonArray;
}
@Override
protected void onPostExecute(JSONArray jsonArray)
{
if(jsonArray!=null)
{
// Do something
}
}
}
public JSONArray ConnectToRESTful(String url,String[] wordList)
{
//the synset data to send
String result = "";
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
for (int i=0;i<wordList.length;i++)
nameValuePairs.add(new BasicNameValuePair("filter",wordList[i]));
InputStream is = null;
//http post
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
catch(Exception e)
{
Log.e("There is a problem. Error in http connection\n", e.toString());
}
//convert response to string
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}
catch(Exception e)
{
Log.e("There is a problem. Error converting result.\n", e.toString());
}
JSONArray jsonArray = null;
try
{
jsonArray = new JSONArray(result);
}
catch (JSONException e)
{
Log.e("There is a problem.\n", e.toString());
}
return jsonArray;
}
내 데이터베이스는 utf8_general_ci 모음에 들어 있으며 문자셋을 사용한다는 것은 무엇을 의미합니까? getBytes에 의해 editText에서 검색된 아랍어 텍스트를 UTF-8로 변환하려고 시도한 다음 srting으로 다시 변환했습니다. byte [] utf8Bytes = synsetString.getBytes ("UTF-8"); encodedStr = 새 문자열 (utf8Bytes, "UTF-8"); 그러나 그것은 효과가 없었습니다. 검색어가 나에게 널 준다. – user1856811
내 수정 된 답변보기 ... – SHAZ
@ user1856811 Android EditText getText(). toString()은 아랍어 텍스트를 직접 가져올 필요가 없습니다. getBytes ("UTF-8"); 당신은 대답을 – Furqan