Wandeln Sie JSON in CSV um

Wandeln Sie JSON in CSV um

Aspose.Cells unterstützt das Umwandeln von einfachen sowie verschachtelten JSON in CSV. Dafür sorgt API**JsonLayoutOptions** und**JsonUtility** Klassen. Das**JsonLayoutOptions**Klasse bietet die Optionen für JSON Layout wie**IgnoreArrayTitle**(ignoriert den Titel, wenn das Array eine Eigenschaft eines Objekts ist) oder**ArrayAsTable**(verarbeitet das Array als Tabelle). Das**JsonUtility**Die Klasse verarbeitet die JSON unter Verwendung der mit der festgelegten Layoutoptionen**JsonLayoutOptions**Klasse.

Das folgende Codebeispiel veranschaulicht die Verwendung von**JsonLayoutOptions**und**JsonUtility** Klassen zum Laden derQuelldatei JSON und generiert dieAusgabedatei CSV.

Beispielcode

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