title: How to get a count value from server into json in android?
body: <p>I am trying to retrieve the number of rows in my server table using json parsing and php in android.
  I have done the following coding in php and I am getting the value also, but I don 't know how to proceed with the json. Please guide me step by step what to do or where I am going wrong. My codes and error logs are as follows:</p>
  
  <p>php code:</p>
  
  <pre><code>&lt;?php
  mysql_connect("localhost","user","pswd");
  mysql_select_db("demo");    
  $username= (isset($_POST['receivenumber'])) ? $_POST['receivenumber'] : '';
  $q=mysql_query("SELECT COUNT(receivenumber) FROM `addtasknew` where `receivenumber` = '$username'") or die(mysql_error());
  $row=mysql_fetch_assoc($q);
  print (json_encode($row));
  mysql_close();
  ?&gt;
  </code></pre>
  
  <p>json codes in android</p>
  
  <pre><code>   String result = null;
      InputStream is = null;
      try{
              HttpClient httpclient = new DefaultHttpClient();
              HttpPost httppost = new HttpPost("http://www.mydomainname.org/task/getmytaskcount.php");
              ArrayList&lt;NameValuePair&gt;  nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
             // String h="123";
              //nameValuePairs.add(new BasicNameValuePair("to",h.toString()));
              nameValuePairs.add(new BasicNameValuePair("receivenumber","9595959595"));
  
               httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
              HttpResponse response = httpclient.execute(httppost); 
  
              HttpEntity entity = response.getEntity();
              is = entity.getContent();
  
              Log.e("log_tag", "connection success "+nameValuePairs);
  
      }
      catch(Exception e)
      {
              Log.e("log_tag", "Error in http connection "+e.toString());
              Toast.makeText(getActivity(), "Connection fail", Toast.LENGTH_SHORT).show();
  
      }
      try
      {
              BufferedReader reader = new BufferedReader(new InputStreamReader(is,HTTP.UTF_8),8);
              StringBuilder sb = new StringBuilder();
              String line = null;
              while ((line = reader.readLine()) != null) 
              {
                      sb.append(line + "\n");
  
              }
              is.close();
  
              result=sb.toString();
            Log.e("log_tag", "result "+result.toString());
      }
      catch(Exception e)
      {
             Log.e("log_tag", "Error converting result "+e.toString());
          Toast.makeText(getActivity(), " Input reading fail", Toast.LENGTH_SHORT).show();
  
      }
      try
      {
  
                   // I don't know wht to do here to get the count value
          JSONArray jArray = new JSONArray(result);
  
            Log.w("Lengh",""+jArray);
               }
      catch(JSONException e)
      {
              Log.e("log_tag", "Error parsing data "+e.toString());
              Toast.makeText(getActivity(), "JsonArray fail", Toast.LENGTH_SHORT).show();
      }
  </code></pre>
  
  <p>error logs:</p>
  
  <pre><code>  E/log_tag(2386): result ?{"COUNT(receivenumber)":"2"}
    E/log_tag(2386): Error parsing data org.json.JSONException: Value {"COUNT(receivenumber)":"2"} of type org.json.JSONObject cannot be converted to JSONArray
  </code></pre>