在c#中的http到php之后,我在代码中获得表单的输出。
public function actionSubmitInspection(){
$data = $_POST;
return (array)$data["check_comments"];
}现在我得到了表格的结果
[
"[{\"id\":26,\"comment\":\"89oiu\"},{\"id\":27,\"comment\":\"comment 2\"}]"
]由于尝试类型转换数组不创建数组,如何将序列化的字符串转换为数组或对象。
发布于 2017-07-24 20:55:14
使用json_decode函数。
public function actionSubmitInspection(){
$data = $_POST;
// replace it
//return (array)$data["check_comments"];
return json_decode($data["check_comments"]);
}输出将是对象数组。
Array
(
[0] => stdClass Object
(
[id] => 26
[comment] => 89oiu
)
[1] => stdClass Object
(
[id] => 27
[comment] => comment 2
)
)发布于 2017-07-24 21:06:03
应该使用json_decode($data["check_comments"]),输出将是stdClass对象的数组
Array
(
[0] => stdClass Object
(
[id] => 26
[comment] => 89oiu
)
[1] => stdClass Object
(
[id] => 27
[comment] => comment 2
)
)或者在第二个param上传递true,json_decode($data["check_comments"], true)和输出将是数组的数组。
Array
(
[0] => Array
(
[id] => 26
[comment] => 89oiu
)
[1] => Array
(
[id] => 27
[comment] => comment 2
)
)https://stackoverflow.com/questions/45289843
复制相似问题