CodeIgniter: json_decode array issues
        Posted  
        
            by thedp
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by thedp
        
        
        
        Published on 2010-05-13T16:40:04Z
        Indexed on 
            2010/05/13
            16:44 UTC
        
        
        Read the original article
        Hit count: 333
        
On my client side I'm sending an ajax request with jQuery in the following matter:
$.post(script.php, { "var1":"something", "var2":"[1,2,3]" }, function(data) { }, "json");
On the server side, in the CodeIgniter's controller I'm receiving the values like so:
$var1 = trim($this->input->post('var1'));
$var2 = trim($this->input->post('var2'));
My question is how do I convert the string in $var2 into a PHP array.
I tried using json_decode($var2, true) but it returns a null since "[1,2,3]" is not a legal JSON string by itself.
Also, if you believe there is a better way for me to read the values on the server-side please show me how.
Thank you.
© Stack Overflow or respective owner