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
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,"GB2312"),8);
我改成这样,他还是出现乱码
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"),8);
如果还乱码,建议检查PHP网页输出后的内容,通过查看浏览PHP网页后的网页源代码判断。
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
也要改为
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "utf-8"));