這是我的 json,肯定合法:
{
"categories": [
{
"id": 1,
"title": "上衣類",
"products": [
{
"id": 8,
"title": "運動服",
"nums": 2,
"price": 60.00
},
{
"id": 10,
"title": "夾克衫",
"nums": 2,
"price": 60.00
}
],
"total_nums": 4,
"total_price": 120.00
},
{
"id": 5,
"title": "汽車類",
"products": [
{
"id": 63,
"title": "布藝兩件套",
"nums": 5,
"price": 250.00
},
{
"id": 65,
"title": "布藝七件套",
"nums": 1,
"price": 200.00
}
],
"total_nums": 6,
"total_price": 450.00
}
],
"count_price": 570.00
}
代碼如下:
public function postWashOrderinfo(Request $request){
$param = $request->all();
// 進行參數(shù)校驗
$validate = new PostWashOrderinfoValidate();
if (!$validate->check($param)) {
return json($validate->getError());
}
$orderinfo = json_decode($param['orderinfo'],true);
return $orderinfo;
}
$orderinfo = json_decode($param['orderinfo'],true);
不管加不加 true 就是 null。
var_dump ($param['orderinfo']),貼出下
string(1122) "{
"categories": [
{
"id": 1,
"title": "上衣類",
"products": [
{
"id": 8,
"title": "運動服",
"nums": 2,
"price": 60.00
},
{
"id": 10,
"title": "夾克衫",
"nums": 2,
"price": 60.00
}
],
"total_nums": 4,
"total_price": 120.00
},
{
"id": 5,
"title": "汽車類",
"products": [
{
"id": 63,
"title": "布藝兩件套",
"nums": 5,
"price": 250.00
},
{
"id": 65,
"title": "布藝七件套",
"nums": 1,
"price": 200.00
}
],
"total_nums": 6,
"total_price": 450.00
}
],
"count_price": 570.00
}"