JSON u CSV ye dönüştür

Contents
[ ]

Aspose.Cells, basit ve iç içe JSON’u CSV’ye dönüştürmeyi destekler. Bunun için API, JsonLayoutOptions ve JsonUtility sınıflarını sağlar. JsonLayoutOptions sınıfı, JSON düzeni için seçenekler sağlar, örneğin IgnoreArrayTitle (dizi bir nesnenin özelliği ise başlığı yoksayar) veya ArrayAsTable (dizi bir tablo olarak işler). JsonUtility sınıfı, JsonLayoutOptions sınıfı tarafından belirlenen düzen seçeneklerini kullanarak JSON’u işler.

Aşağıdaki kod örneği, JsonLayoutOptions ve JsonUtility sınıflarını yüklemek için kullanır, kaynak JSON dosyası ‘ı alır ve çıktı CSV dosyasını oluşturur.

Örnek Kod

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Source directory
String sourceDir = Utils.Get_SourceDirectory();
//Output directory
String outputDir = Utils.Get_OutputDirectory();
// Read JSON file
String str = new String(Files.readAllBytes(Paths.get(sourceDir + "SampleJson.json")));
// Create empty workbook
Workbook workbook = new Workbook();
// Get Cells
Cells cells = workbook.getWorksheets().get(0).getCells();
// Set JsonLayoutOptions
JsonLayoutOptions importOptions = new JsonLayoutOptions();
importOptions.setConvertNumericOrDate(true);
importOptions.setArrayAsTable(true);
importOptions.setIgnoreArrayTitle(true);
importOptions.setIgnoreObjectTitle(true);
JsonUtility.importData(str, cells, 0, 0, importOptions);
// Save Workbook
workbook.save(outputDir + "SampleJson_out.csv");