【发布时间】:2011-08-09 14:44:16
【问题描述】:
我有一个应该从网络服务读取 mysql 数据库的 android 应用程序。
这是网络服务中的代码:
$q=mysql_query("SELECT * FROM Rates");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
这是我的应用程序中的代码:
public void getQuery() {
String result = "";
InputStream is;
try{
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://dakatora.co.il/android/androidsql.php");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
is = new InputStream() {
@Override
public int read() throws IOException {
// TODO Auto-generated method stub
return 0;
}
};
}
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
由于某种原因,结果字符串没有得到查询,而是只得到“\n”。 谁能告诉我怎么了?
【问题讨论】:
标签: php android web-services json