Converti JSON in CSV

Converti JSON in CSV

Aspose.Cells supporta la conversione di JSON semplici e nidificati in CSV. Per questo, API fornisce**JsonLayoutOptions** e**JsonUtility** classi. Il**JsonLayoutOptions**class fornisce le opzioni per il layout JSON come**IgnoreArrayTitle**(ignora il titolo se l’array è una proprietà di un oggetto) o**ArrayAsTable**(elabora l’array come una tabella). Il**JsonUtility**class elabora lo JSON utilizzando le opzioni di layout impostate con il file**JsonLayoutOptions**classe.

L’esempio di codice seguente illustra l’utilizzo di**JsonLayoutOptions**e**JsonUtility** classi per caricare il filefonte JSON file e genera iloutput CSV file.

Codice d’esempio

// 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");