title: Android How to create a json from array and send to php server
body: <p>I am working on an application that generates list of install applications and create a json and send the json to my php server. At php server the I have to get all data and process it acordingly.</p>
  
  <p>This is the code that generates list of installed applications:</p>
  
  <pre><code>List&lt;PackageInfo&gt; apps = getPackageManager().getInstalledPackages(PackageManager.GET_META_DATA);
  
      ArrayList&lt;String[]&gt; aux = new ArrayList();
  
      for (int i = 0; i &lt; apps.size(); i++)
      {
          if (apps.get(i).versionCode != 0 &amp;&amp; ((apps.get(i).applicationInfo.flags &amp; ApplicationInfo.FLAG_SYSTEM) != 1))
          {
              String[] temp = new String[2];
  
              String name = apps.get(i).packageName;
              String versionName = apps.get(i).versionName;
              temp[0] = name;
              temp[1] = versionName;
              aux.add(temp);
          }
      }
  </code></pre>
  
  <p>This is the code to send it in json form to php server:</p>
  
  <pre><code>try
          {
  JSONObject obj = new JSONObject();
          obj.put("Applications", aux);
              URL url = new URL(IPClass.SERVERPath + "update.php");
  
              HttpURLConnection conn = (HttpURLConnection) url.openConnection();
              conn.setReadTimeout(15000);
              conn.setConnectTimeout(15000);
              conn.setRequestMethod("POST");
              conn.setDoInput(true);
              conn.setDoOutput(true);
              conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
  
              OutputStream os = conn.getOutputStream();
              BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
              //OutputStreamWriter writer = new OutputStreamWriter(os);
  
              writer.write(String.valueOf(aux));
              writer.flush();
              writer.close();
              os.close();
  
  
              InputStream input = conn.getInputStream();
              BufferedReader reader = new BufferedReader(new InputStreamReader(input));
              StringBuilder result = new StringBuilder();
              String line;
  
              while ((line = reader.readLine()) != null) {
                  result.append(line);
              }
              Log.d("doInBackground(Resp)", result.toString());
  
          }
          catch(Exception ex)
          {
              Log.d("Ex", ex.toString());
          }
  </code></pre>
  
  <p>The problem is that the json is not getting generated properly and second how can i get it on php server! </p>
  
  <p>Any help please!
  Thanks</p>