Php 如何取消序列化数组字符串
这就是我创建数组的方式Php 如何取消序列化数组字符串,php,jquery,serialization,Php,Jquery,Serialization,这就是我创建数组的方式 var list = $("#sortable").sortable('toArray'); $.ajax({ type: 'POST', url: " some path ", data: { "list" : JSON.stringify(list) }, success: function(data) {} }); 在DB中看起来是这样的 ["34","37","38","40","41","42","43
var list = $("#sortable").sortable('toArray');
$.ajax({
type: 'POST',
url: " some path ",
data: { "list" : JSON.stringify(list) },
success: function(data) {}
});
在DB中看起来是这样的
["34","37","38","40","41","42","43","44","45","48","49","50"]
不,我想在php中将其用作数组。如何将此字符串转换为数组?我尝试了unserialize()
方法,但这似乎不是正确的方法。您可以使用以下函数:
$arr = json_decode($_POST["list"])
您可以使用以下功能:
$arr = json_decode($_POST["list"])
不要字符串化json对象,让jQuery为您处理它
$.ajax({
type: 'POST',
url: " some path ",
data: { "list" : list }, // here, it's not necessary to stringify the json object.
success: function(data) {}
});
然后通过
$\u POST['list']
在php中获得数组。不要字符串化json对象,让jQuery为您处理
$.ajax({
type: 'POST',
url: " some path ",
data: { "list" : list }, // here, it's not necessary to stringify the json object.
success: function(data) {}
});
然后通过
$\u POST['list']
php的unserialize
仅用于用php的serialize
序列化的字符串,您实际上是在发送JSON,因此,JSON\u decode
。php的unserialize
仅用于用php的serialized
序列化的字符串,实际上您正在发送JSON,因此,JSON\u decode
。