如何反序列化数组字符串

时间:2012-06-27 07:35:54

标签: 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","44","45","48","49","50"]

不,我想在php中使用它作为数组。如何将此字符串转换为数组?我尝试使用unserialize()方法,但这似乎不太可行。

2 个答案:

答案 0 :(得分:3)

您可以使用json_decode功能:

$arr = json_decode($_POST["list"])

答案 1 :(得分:1)

不要对json对象进行字符串化,让jQuery为你处理。

$.ajax({
       type: 'POST',
       url: " some path ",
       data: { "list" : list }, // here, it's not necessary to stringify the json object.
       success: function(data) {}
});

然后你通过$_POST['list']在php中获取数组。

相关问题