title: get error when json_decode string from ajax post
body: <p>I try send string to controller, the string is json format, when send to controller, i get error and can't decode my json string in that controller. I try to encode first in my controller, but still get error. And the error is </p>
  
  <blockquote>
    <p>"json_decode() expects parameter 1 to be string, array given",
    exception: "ErrorException",</p>
  </blockquote>
  
  <p>here in my json string </p>
  
  <pre><code>"{ "data" : 
  [{
  "id": "TNI01",
   "jenis_bayar": "TUNAI",
  "no_kartu": "kosong",
  "nominal": "10000",
  "seq": "1"
  } , 
  {
  "id": "DEB01",
  "jenis_bayar": "DEBIT BCA",
  "no_kartu": "786382432432",
  "nominal": "20000",
  "seq": "2"
  }]
  }"
  </code></pre>
  
  <p>here the controller</p>
  
  <pre><code>public function ArrayPostToTablePembayaran(Request $request)
      {
  
         $data = json_decode($request-&gt;datajson, true);
  
         foreach ($data-&gt;data as $datas) 
         {
            $id         = $datas-&gt;id;
            $jenisbayar = $datas-&gt;jenis_bayar;
            $nokartu    = "";
  
            if($datas-&gt;no_kartu == "kosong")
            {
                $nokartu ="";
            }
  
            $nominal    = $datas-&gt;nominal;
            $seq        = $data-&gt;seq;
            $this-&gt;PosToTablePembayaran1($id , $jenisbayar , $nokartu , $nominal , $seq); 
         }
      }
  </code></pre>
  
  <p>and here the ajax script for parse json string to controller</p>
  
  <pre><code>function PembayaranKeDatabase1(arraystring)
              {
                $.ajax(
                    {
                        type    : "POST",
                        url     : "{{ url('/trx_bayar') }}",
                        data    : { datajson : JSON.parse(arraydata) } ,
                        dataType: "json",
                        success: function(data){
  
                        },
                        error: function() {
  
                        }
                    });
              }
  </code></pre>
  
  <p>thanks before</p>