{"id":"1","firstname":"john","lastname":"doe"}
这是我的JSON格式。我想上传CSV文件。将从中显示JSON格式。 CSV文件格式如下所示:我正在使用mongo db
Id FirstName LastName
1 john doe
2 doe john
答案 0 :(得分:0)
使用json_decode($json_string, TRUE)
将json字符串转换为数组
然后创建一个CSV文件
Example
header('Content-Type: application/excel');
header('Content-Disposition: attachment; filename="sample.csv"');
$fp = fopen('php://output', 'w');
foreach ( $data as $line ) {
$val = explode(",", $line);
fputcsv($fp, $val);
}
fclose($fp);