Android应用程序连接php文件和条件简单

Android应用程序连接php文件和条件简单,php,android,json,Php,Android,Json,我需要我的android应用程序连接到一个PHP文件(只需在表上进行选择并以JSON格式显示结果),我如何将我的应用程序连接到PHP文件并生成一个条件?例如: JSON: 条件: if (ResultPHP==hola){ //se encontró correctamente 'hola' }else{ //no se encontró 'hola' } 目前,我的连接代码是: public class QRpost { public static void postData()

我需要我的android应用程序连接到一个PHP文件(只需在表上进行选择并以JSON格式显示结果),我如何将我的应用程序连接到PHP文件并生成一个条件?例如:

JSON:

条件:

if (ResultPHP==hola){
 //se encontró correctamente 'hola'
}else{
 //no se encontró 'hola'
}
目前,我的连接代码是:

 public class QRpost {

 public static void postData() {
 // Create a new HttpClient and Post Header
 HttpClient httpclient = new DefaultHttpClient();
 HttpPost httppost = new HttpPost("qr.php");
 try {
   // Execute HTTP Post Request
   HttpResponse response = httpclient.execute(httppost);
   HttpEntity entity = response.getEntity();
   InputStream webs = entity.getContent();
   try{
    BufferedReader reader = new BufferedReader(new InputStreamReader(webs,"iso-8859-1"),8);
    webs.close();
   }catch(Exception e){
    Log.e("log_tag", "Error al convertir el resultado");
   }
  } catch (ClientProtocolException e) {
   // TODO Auto-generated catch block
   } catch (IOException e) {
   // TODO Auto-generated catch block
  }
  }
 }

有人能帮我吗?对不起我的英语:(

在创建
BufferedReader
之后,您需要将每一行读入
StringBuilder

        BufferedReader reader = new BufferedReader(new InputStreamReader(webs,"iso-8859-1"),8);

        StringBuilder builder = new StringBuilder();
        String line = null;

        while ((line = reader.readLine()) != null) {

            builder.append(line);
        }

        webs.close();

        String json = builder.toString();
json
变量将包含所有json作为
String
。然后需要在该字符串上使用json解析器从json中获取所需的变量。有关如何解析字符串,请参阅
JSONObject
JSONArray

        BufferedReader reader = new BufferedReader(new InputStreamReader(webs,"iso-8859-1"),8);

        StringBuilder builder = new StringBuilder();
        String line = null;

        while ((line = reader.readLine()) != null) {

            builder.append(line);
        }

        webs.close();

        String json = builder.toString();