JSON を CSV に変換

Aspose.Cells は、単純な JSON とネストされた JSON を CSV に変換することをサポートします。JsonLayoutOptionsJsonユーティリティクラス。のJsonLayoutOptionsクラスは、次のような JSON レイアウトのオプションを提供しますIgnoreArrayTitle(配列がオブジェクトのプロパティである場合、タイトルは無視されます) またはArrayAsTable(配列をテーブルとして処理します)。のJsonユーティリティクラスは、レイアウト オプション セットを使用して JSON を処理します。JsonLayoutOptionsクラス。

次のコード サンプルは、JsonLayoutOptionsJsonユーティリティロードするクラスソース JSON ファイルを生成し、出力 CSV ファイル.

サンプルコード

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Source directory
String sourceDir = Utils.Get_SourceDirectory();
//Output directory
String outputDir = Utils.Get_OutputDirectory();
// Read JSON file
String str = new String(Files.readAllBytes(Paths.get(sourceDir + "SampleJson.json")));
// Create empty workbook
Workbook workbook = new Workbook();
// Get Cells
Cells cells = workbook.getWorksheets().get(0).getCells();
// Set JsonLayoutOptions
JsonLayoutOptions importOptions = new JsonLayoutOptions();
importOptions.setConvertNumericOrDate(true);
importOptions.setArrayAsTable(true);
importOptions.setIgnoreArrayTitle(true);
importOptions.setIgnoreObjectTitle(true);
JsonUtility.importData(str, cells, 0, 0, importOptions);
// Save Workbook
workbook.save(outputDir + "SampleJson_out.csv");