当前位置: 代码迷 >> Android >> android传字符串给PHP,可是PHP为啥解析出来是乱码
  详细解决方案

android传字符串给PHP,可是PHP为啥解析出来是乱码

热度:98   发布时间:2016-05-01 15:01:10.0
android传字符串给PHP,可是PHP为什么解析出来是乱码
ArrayList nameValuePairs = new ArrayList();
nameValuePairs.add(new BasicNameValuePair("tb",tb_tbname));
nameValuePairs.add(new BasicNameValuePair("field",sdfield));
nameValuePairs.add(new BasicNameValuePair("value",sdvalue));
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://219.229.167.60/ljsql/"+op+".php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
 
String line=null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
//paring data
 
try{
jArray = new JSONArray(result);
}catch(JSONException e1){
// Toast.makeText(getBaseContext(), "No City Found" ,Toast.LENGTH_LONG).show();
} catch (ParseException e1) {
e1.printStackTrace();
}
return jArray;

为什么我PHP解析出来变成\u001a\u001a

------解决方案--------------------
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
改为
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"GB2312"),8);
  相关解决方案