Konvertera JSON till CSV
Contents
[
Hide
]
Konvertera JSON till CSV
Aspose.Cells stöder konvertering av såväl enkla som kapslade JSON till CSV. För detta tillhandahåller API**JsonLayoutOptions** och**JsonUtility** klasser. De**JsonLayoutOptions**klass ger alternativen för JSON layout som**IgnoreArrayTitle**(ignorerar titeln om arrayen är en egenskap hos ett objekt) eller**ArrayAsTable**(behandlar arrayen som en tabell). De**JsonUtility**klass bearbetar JSON med hjälp av layoutalternativen som ställts in med**JsonLayoutOptions**klass.
Följande kodexempel visar användningen av**JsonLayoutOptions**och**JsonUtility** klasser för att laddakällfil JSON och genererarutgång CSV fil.
Exempelkod
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"); |