تحويل JSON إلى CSV

Contents
[ ]

تدعم Aspose.Cells تحويل JSON البسيط والمتداخل إلى CSV. لهذا الغرض، توفر الواجهة البرمجية النطاقية JsonLayoutOptions و JsonUtility. يوفر الفئة JsonLayoutOptions الخيارات لتخطيط JSON مثل IgnoreArrayTitle (يتجاهل العنوان إذا كان المصفوفة خاصية لكائن) أو ArrayAsTable (يعالج المصفوفة كجدول). تقوم الفئة JsonUtility بمعالجة JSON باستخدام خيارات التخطيط المضبوطة باستخدام الفئة JsonLayoutOptions.

يوضح الكود النموذجي التالي استخدام فئتي JsonLayoutOptions و JsonUtility لتحميل ملف JSON المصدر وإنشاء ملف CSV الناتج.

كود عينة

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