안녕하세요, 저는 json을 csv로 변환하는 데 작은 문제가 있습니다. 나는이 [{"name":"Wayne","age":28},{"name":"John","age":21},{"name":"Sara","age":24}]
하고 작업을 완벽하게 같은 다른 JSON 형식으로 시도json을 csv로 PHP를 사용하여 변환
$jsonString = '{"cod":"200","calctime":0.3107,"cnt":15,"list":[{"id":2208791,"name":"Yafran","coord":{"lon":12.52859,"lat":32.06329},"main":{"temp":9.68,"temp_min":9.681,"temp_max":9.681,"pressure":961.02,"sea_level":1036.82,"grnd_level":961.02,"humidity":85},"dt":1485784982,"wind":{"speed":3.96,"deg":356.5},"rain":{"3h":0.255},"clouds":{"all":88},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}]}]}';
//Decode the JSON and convert it into an associative array.
$jsonDecoded = json_decode($jsonString, true);
//Give our CSV file a name.
$csvFileName = 'file.csv';
//Open file pointer.
$fp = fopen($csvFileName, 'w');
//Loop through the associative array.
foreach($jsonDecoded as $row){
//Write the row to the CSV file.
fputcsv($fp, $row);
}
//Finally, close the file pointer.
fclose($fp);
?>
: 다음은 내 코드입니다. 내 코드를 수정하여 csv 형식으로 올바르게 저장하는 방법.
사진 : 이 지금은 같은 저장 : 이 같은 저장해야 : 이
누군가가 나를 도울 수 있습니까? 이 작동
사용이 https://github.com/danmandle/JSON2CSV –
이해 귀하의 데이터 구조 즉'$ jsonDecoded' 배열 그리고 당신이 뭘 잘못하고 있는지 볼 수 – RiggsFolly