حوّل JSON إلى CSV
Contents
[
Hide
]
يدعم Aspose.Cells التحويل البسيط والمتداخل من JSON إلى CSV. لهذا الغرض ، يوفر APIJsonLayoutOptionsوJsonUtilityالطبقات. الJsonLayoutOptionsتوفر class خيارات تخطيط JSON مثلIgnoreArrayTitle(يتجاهل العنوان إذا كانت المصفوفة خاصية لكائن) أوArrayAsTable(يعالج المصفوفة كجدول). الJsonUtilityيقوم class بمعالجة JSON باستخدام خيارات التخطيط التي تم ضبطها باستخدامJsonLayoutOptionsصف دراسي.
يوضح نموذج التعليمات البرمجية التالي استخدامJsonLayoutOptionsوJsonUtilityفئات لتحميلالمصدر JSON ملفويولد الملف الإخراج CSV.
عينة من الرموز
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-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"); |