JSONをCSVに変換する

JSONをCSVに変換

Aspose.Cellsは、単純なJSONだけでなく、入れ子のJSONをCSVに変換するサポートを提供します。このために、APIはJsonLayoutOptionsおよびJsonUtilityクラスを提供します。JsonLayoutOptionsクラスは以下のようなJSONレイアウトのオプションを提供します。

以下のコードサンプルは、ソースのJSONファイルをロードして出力のCSVファイルを生成する方法を示しています。

サンプルコード

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
// Read JSON file
string str = File.ReadAllText(sourceDir + "SampleJson.json");
// Create empty workbook
Workbook workbook = new Workbook();
// Get Cells
Cells cells = workbook.Worksheets[0].Cells;
// Set JsonLayoutOptions
JsonLayoutOptions importOptions = new JsonLayoutOptions();
importOptions.ConvertNumericOrDate = true;
importOptions.ArrayAsTable = true;
importOptions.IgnoreTitle = true;
JsonUtility.ImportData(str, cells, 0, 0, importOptions);
// Save Workbook
workbook.Save(outputDir + @"SampleJson_out.csv");