title: Sending & Reading using JSON
body: <p>My Android Application Reads JSON Data from PHP File according to username and password Sent from Application also as JSON.<br>What I have reached for now that I can Only Read by specifying the username and password, No Sending for username and password from App happens..<br><br>
  My question is, Is it possible to Read and Also POST Using JSONParse ??<br> 
  Please Take a look at the JSONParse Method I've Added a part that's commented because it's not working "Is it possible to Send Username and Password along with Reading status from Database Using JSON"</p>
  
  <p><strong>JSONParse</strong></p>
  
  <pre><code>private class JSONParse extends AsyncTask&lt;String, String, JSONObject&gt; {
               private ProgressDialog pDialog;
              @Override
              protected void onPreExecute() {
                  super.onPreExecute();
  
                  pDialog = new ProgressDialog(fishtank.this);
                  pDialog.setMessage("Getting Data ...");
                  pDialog.setIndeterminate(false);
                  pDialog.setCancelable(true);
                  pDialog.show();
  
              }
  
              @Override
              protected JSONObject doInBackground(String... args) {
  
              /*Temp
                  SharedPreferences settings =  getSharedPreferences("mySettings", Activity.MODE_PRIVATE);
                   us = settings.getString("storedWifiUser", "");
                      ps = settings.getString("storedWifiPass", "");
                   try {
                       JSONObject json = new JSONObject(); 
                       json.put("user", us); 
                       json.put("pass", ps);
  
                       postData(json);
  
  
                   } catch (JSONException e) {
                       e.printStackTrace();}  Temp */
                  JSONParser jParser = new JSONParser();   
                  // Getting JSON from URL
                  JSONObject json = jParser.getJSONFromUrl(url);
                  return json;
              }
  
              public void postData(JSONObject json) throws JSONException {
                  HttpClient httpclient = new DefaultHttpClient();
  
                  try { 
                      HttpPost httppost = new HttpPost(url);
  
                      List&lt;NameValuePair&gt; nvp = new ArrayList&lt;NameValuePair&gt;(2);    
                      nvp.add(new BasicNameValuePair("json", json.toString()));
                      //httppost.setHeader("Content-type", "application/json");  
                      httppost.setEntity(new UrlEncodedFormEntity(nvp));
                      HttpResponse response = httpclient.execute(httppost); 
                      Log.i("JSON Response : ",json.toString().trim());
                      if(response != null) {
                          InputStream is = response.getEntity().getContent();
                          //input stream is response that can be shown back on android
                      }
  
                  }catch (Exception e) {
                      e.printStackTrace();
                  } 
              }
              //Temp
               @Override
  
               protected void onPostExecute(JSONObject json) {
                   pDialog.dismiss();
                   try {
                      // Log.i("JSON Response : ",json.toString().trim());
                      // Log.i("JSON Response : "+json.toString().trim());
  
                      // System.out.println("JSON Response : "+json.toString().trim());
                       JSONObject c = json.getJSONObject("status");
                       String tog1="";
                       String tog2="";
                       String tog3="";
                       if(c.has("fil"))
  
                              tog1 = c.getString("fil");
  
                          if(c.has("HEA"))
                           tog2 = c.getString("HEA");
  
                          if(c.has("LED"))
                              tog3 = c.getString("LED");
  
                          Log.i("JSON Response : ",json.toString().trim());
                                          if(tog1.equals("ON"))
                                          {   toggle1.setChecked(true);}
                                          else{ toggle1.setChecked(false);}
                                               if(tog2.equals("ON"))
                                               {   toggle2.setChecked(true);}
                                               else{   toggle2.setChecked(false);}
                                               if(tog3.equals("ON"))
                                               {    toggle3.setChecked(true);}
                                               else{toggle3.setChecked(false);}
  
                               } catch (JSONException e) {
                                   e.printStackTrace();
                               }
  
               }
  
  
  
  
  
  
          }//End Json
  </code></pre>
  
  <p><strong>PHP File</strong></p>
  
  <pre><code>&lt;?php
  
  $con=mysqli_connect("localhost","root","123","pet_home");
  if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
  
  // if(isset($_POST['json'])){
      //    $json=$_POST['json'];
      //    $data2=json_decode($json,TRUE);
      //    $u=$data2-&gt;{'user'};
     //     $p=$data2-&gt;{'pass'};
              $result = mysqli_query($con,"SELECT * FROM users WHERE username='osama' AND password='123'");
              $row_cnt = mysqli_num_rows($result);
  //$row_cnt=1;
               if($row_cnt&gt;0){     
                   $row = mysqli_fetch_array($result); 
                  $data = array('success'=&gt;true, 'error'=&gt;'',  'status'=&gt;array("fil" =&gt; $row['filter_st'], "HEA"=&gt; $row['heat_st'], "LED" =&gt;$row['led_st'])); 
               }else{
                  $data = array('success'=&gt;false, 'error' =&gt; 'No records found');
               }               
  
     //  }else{
      //     $data = array('success'=&gt;false, 'error' =&gt; 'No POST value from Android App');
    //   }
  
       echo json_encode($data);
  
  mysqli_close($con);
  
  
  ?&gt;
  </code></pre>