Converti JSON in CSV

Convertire JSON in CSV

Aspose.Cells supporta la conversione di JSON semplice e annidato in CSV. A tale scopo, l’API fornisce JsonLayoutOptionsJsonUtility. La classe JsonLayoutOptions 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). La classe JsonUtility elabora il JSON utilizzando le opzioni di layout impostate con la classe JsonLayoutOptions.

Il seguente esempio di codice dimostra l’uso delle classi JsonLayoutOptions e JsonUtility per caricare il file JSON di origine e genera il file CSV di output.

Codice di 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");