こんにちは私は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