以下代码未从 PHP 文件中的这段代码接收到 PHP 文件的输出,即“羽毛球协会”:
print(json_encode($row['Description']));
如果有人能发现错误,那就太好了。'result' 和 'is' 都是空变量:
public class BackgroundAsyncTask extends AsyncTask<Void, String, Void> {
protected Void doInBackground(Void... params) {
//http post
try{
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet("http://ntusocities.host22.com/post.php");
HttpResponse response = client.execute(get);
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);
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("log_tag", "Error converting result "+e.toString());
}
//parse json data
try {
JSONObject userObject = new JSONObject(result);
info = userObject.getString("Description");
}
catch(Exception ex){
}
return null;
}
}
非常感谢!