title: How to send json from android to php?
body: <p>To post json from android to php, i used Volley library <code>StringRequest</code> object. </p>
  
  <pre><code>StringRequest sr = new StringRequest(Request.Method.POST,url, new Response.Listener&lt;String&gt;() {
              @Override
              public void onResponse(String response) {
                  // some code
              }
          }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                  //some code
              }
          }){
              @Override
              protected Map&lt;String,String&gt; getParams(){
                  Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
                  ArrayList&lt;Command&gt; commands = MyApplication.readFromPreferences(getActivity(), Constants.COMMAND);
                  String jsonCommands = new Gson().toJson(commands);
                  params.put("commands", jsonCommands);
                  return params;
              }
          };
  </code></pre>
  
  <p>And to catch the data in php and verify if it was sent correcttly, I used this</p>
  
  <pre><code>echo $_POST["commands"]; 
  </code></pre>
  
  <p><em>Output:</em></p>
  
  <pre><code>[{\"product\":{\"category_id\":1,\"created_at\":\"2015-06-13 17:49:58\",\"description\":\"CF77 COIN FINDER\",\"url_image\":\"IMG_76ECDC-707E7E-70AC81-0A1248-4675F3-F0F783.jpg\",\"name\":\"CF77 COIN FINDER\",\"pid\":12,\"price\":500.0},\"product_quantity\":3},{\"product\":{\"category_id\":1,\"created_at\":\"2015-06-13 17:49:58\",\"description\":\"JEOSONAR 3D DUAL SYSTEM\",\"url_image\":\"IMG_2D9DF0-2EB7E9-ED26C0-2C833B-B6A5C5-5C7C02.jpg\",\"name\":\"JEOSONAR 3D DUAL SYSTEM\",\"pid\":15,\"price\":500.0},\"product_quantity\":1},{\"product\":{\"category_id\":1,\"created_at\":\"2015-06-13 17:49:58\",\"description\":\"MAKRO POINTER\",\"url_image\":\"IMG_Macro.jpg\",\"name\":\"MAKRO POINTER\",\"pid\":18,\"price\":500.0},\"product_quantity\":3}]
  </code></pre>
  
  <p>I have noticed that when sending the json string with POST Method using Volley library, a lot of anti-slashes have been added to escape double quotes.</p>
  
  <p><em>So here comes my problem:</em> </p>
  
  <p>I want to decode json to an array of objects in php, so i used </p>
  
  <pre><code>$commands = json_decode( $_POST["commands"],true);
  </code></pre>
  
  <p>But it always returns an empty array because of the invalide above json (caused by the anti-slashes).</p>
  
  <p>Is there a method in php or in java SDK providing a contract for sending and receiving json without having this kind of problems? Or should i reformat the json in php and delete all the anti-slashes?</p>