Convertir JSON a CSV
Contents
[
Hide
]
Convertir JSON a CSV
Aspose.Cells admite la conversión simple y anidada de JSON a CSV. Para esto, API proporciona**JsonLayoutOptions** y**JsonUtility** clases Él**JsonLayoutOptions**class proporciona las opciones para el diseño JSON como**IgnorarTituloArray**(ignora el título si la matriz es una propiedad de un objeto) o**ArrayAsTable**(procesa la matriz como una tabla). Él**JsonUtility**La clase procesa el JSON usando las opciones de diseño establecidas con el**JsonLayoutOptions**clase.
El siguiente ejemplo de código demuestra el uso de**JsonLayoutOptions**y**JsonUtility** Clases para cargar elfuente JSON archivo y genera laarchivo de salida CSV.
Código de muestra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |