I store encoded 开发者_如何学Pythonarrays in a database, and when I try to decode it, it will return with null.
[{"id":13,"qty":"1"}]
Arrays are encoded with PHP, so I have no idea what the problem might be.
Thanks
Personally the serialize(); and unserialize(); functions would be better if you want to store an array in a database. JSON functions should be used for JSON strings to be returned to JavaScript.
$array = array('data','more data','superdata'=>'even more data');
$array = serialize($array);
// Store array in database after serialized
Then to turn the data back into an array from the database, you would...
// Fetch the data from the database
$data = $row['myDataArray'];
$array = unserialize($data);
echo $array['superdata']; // Would produce: "even more data"
Hopefully this will help you out a bit with your issues. If you did need to turn it into JSON to send to JavaScript, then you would use the json_encode($array); function.
Try to print:
json_last_error()
I had a similar issue, though in a different context. In my case, I was trying to decode a JSON string, encoded with Javascript JSON.stringify, store it in a hidden text field and decode it back in PHP after the page is POSTed. I found, applying a stripslashes function before decoding was helpful. 
$arrMyOutput = json_decode(stripslashes($yourJSON_string_goes_here));
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论