I implement a search on the Mysql table from the android. When loading a json search result, Russian characters are displayed as question marks, everything is normal with English. Also, when sending a POST request for the search, I do not understand Russian characters.

public class Parser extends AsyncTask<Void,Void,Integer> { Context c; String data; ListView lv; ArrayList<String> names=new ArrayList<>(); public Parser(Context c, String data, ListView lv) { this.c = c; this.data = data; this.lv = lv; } @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected Integer doInBackground(Void... params) { return this.parse(); } @Override protected void onPostExecute(Integer integer) { super.onPostExecute(integer); if(integer==1) { //BIND TO LISTVIEW ArrayAdapter adapter=new ArrayAdapter(c,android.R.layout.simple_list_item_1,names); lv.setAdapter(adapter); }else { Toast.makeText(c,"Unable to Parse",Toast.LENGTH_SHORT).show(); } } private int parse() { try { JSONArray ja=new JSONArray(data); JSONObject jo; names.clear(); for(int i=0;i<ja.length();i++) { jo=ja.getJSONObject(i); String id=jo.getString("id"); String name=jo.getString("name"); String price=jo.getString("price"); names.add(id); names.add(name); names.add(price); } return 1; } catch (JSONException e) { e.printStackTrace(); } return 0; } 

}

 public class DataPackager { String query; public DataPackager(String query) { this.query = query; } public String packageData() { JSONObject jo=new JSONObject(); StringBuffer queryString=new StringBuffer(); try { jo.put("Query",query); Boolean firstValue=true; Iterator it=jo.keys(); do { String key=it.next().toString(); String value=jo.get(key).toString(); if(firstValue) { firstValue=false; }else { queryString.append("&"); } queryString.append(URLEncoder.encode(key,"UTF-8")); queryString.append("="); queryString.append(URLEncoder.encode(value,"UTF-8")); }while (it.hasNext()); return queryString.toString(); } catch (JSONException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; } 

}

 public class SenderReceiver extends AsyncTask<Void,Void,String>{ Context c; String urlAddress; String query; ListView lv; ImageView noDataImg,noNetworkImg; ProgressDialog pd; public SenderReceiver(Context c, String urlAddress, String query, ListView lv,ImageView...imageViews) { this.c = c; this.urlAddress = urlAddress; this.query = query; this.lv = lv; this.noDataImg=imageViews[0]; this.noNetworkImg=imageViews[1]; } @Override protected void onPreExecute() { super.onPreExecute(); pd = new ProgressDialog(c); pd = new ProgressDialog(c, R.style.MyTheme); pd.setCancelable(false); pd.setProgressStyle(android.R.style.Widget_ProgressBar_Small); pd.show(); } @Override protected String doInBackground(Void... params) { return this.sendAndReceive(); } @Override protected void onPostExecute(String s) { super.onPostExecute(s); pd.dismiss(); //RESET LISTVIEW lv.setAdapter(null); if(s != null) { if(!s.contains("null")) { Parser p=new Parser(c,s,lv); p.execute(); noNetworkImg.setVisibility(View.INVISIBLE); noDataImg.setVisibility(View.INVISIBLE); }else { noNetworkImg.setVisibility(View.INVISIBLE); noDataImg.setVisibility(View.VISIBLE); } }else { noNetworkImg.setVisibility(View.VISIBLE); noDataImg.setVisibility(View.INVISIBLE); } } private String sendAndReceive() { HttpURLConnection con=Connector.connect(urlAddress); if(con==null) { return null; } try { OutputStream os=con.getOutputStream(); BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(os,"UTF-8")); bw.write(new DataPackager(query).packageData()); bw.flush(); //RELEASE RES bw.close(); os.close(); //SOME RESPONSE ???? int responseCode=con.getResponseCode(); //DECODE if(responseCode==con.HTTP_OK) { //RETURN SOME DATA stream InputStream is=con.getInputStream(); //READ IT BufferedReader br=new BufferedReader(new InputStreamReader(is,"UTF-8")); String line; StringBuffer response=new StringBuffer(); if(br != null) { while ((line=br.readLine()) != null) { response.append(line+"\n"); } }else { return null; } return response.toString(); }else { return String.valueOf(responseCode); } } catch (IOException e) { e.printStackTrace(); } return null; } 

} enter image description here

Php

  $con=mysqli_connect($host,$username,$pwd,$db) or die('Unable to connect'); if(mysqli_connect_error($con)) { echo "Failed to Connect to Database ".mysqli_connect_error(); } $name=$_POST['Query']; $sql = "SELECT id,name,price FROM `products` WHERE name LIKE '%$name%'"; $query=mysqli_query($con,$sql); if($query) { while($row=mysqli_fetch_array($query)) { $data[]=$row; } echo(json_encode($data)); }else { echo('Not Found '); } mysqli_close($con); ?> 
  • And at you the data is stored in utf8? - pavel163
  • Yes, the utf8_general_ci encoding is Damir
  • And the title, which is sent on approach to the page what? (In the sense - what format is indicated there) - Daniel Protopopov
  • Are you about a URL? Or in the PHP file itself - Damir

0