我正在尝试在JSON中返回JSON。我尝试过,但无法弄清楚。
Controller.php
$output_sum = json([
"sold_price"=>1,
"item_cost"=> 2,
"fees"=>3,
"profit"=>4
]);
return response()->json([
'spreadsheet_grid'=>"hello",
'spreadsheet_summary'=>$output_sum
]);
答案 0 :(得分:4)
我认为一次编码整个数组会更好,更简单,例如:
$output_sum = [
"sold_price"=>1,
"item_cost"=> 2,
"fees"=>3,
"profit"=>4
];
return response()->json([
'spreadsheet_grid' => "hello",
'spreadsheet_summary' => $output_sum
]);
生成的JSON格式如下:
{
"spreadsheet_grid":"hello",
"spreadsheet_summary":
{
"sold_price":1,
"item_cost":2,
"fees":3,
"profit":4
}
}