首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

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

2012-09-01 
android传字符串给PHP,可是PHP为什么解析出来是乱码ArrayList nameValuePairs new ArrayList() nameVal

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);

热点排行