以下代码仅显示第一条记录。谁能纠正我的错误。
使用这个尝试我建立了与 php 的连接
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/androidphp/1/index.php");
httppost.setEntity(new UrlEncodedFormEntity(namevaluepairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
if(response.getStatusLine().getStatusCode() != 200){
Log.d("MyApp", "Server encountered an error");
}
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF8"));
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();
}
使用这个 try 块我打印了所有值
try{
jArray = new JSONArray(result);
JSONObject json_data = null;
for(int i=0; i<jArray.length(); i++){
json_data = jArray.getJSONObject(i);
outputStream.append("Id="+json_data.getString("id"));
outputStream.append("Name="+json_data.getString("name"));
}