导出带有阿拉伯语单词android的CSV文件

时间:2019-04-12 23:18:35

标签: java android csv gson export-to-csv

我正在使用打开的csv库将JSON导出到csv文件,但是阿拉伯语单词显示为formatزخباÙزØ这种格式。

我尝试使用“ ISO-8859-1”对JSON进行编码,并使用“ UTF-8”对JSON进行解码,但是结果是单词开始出现在这个单词中?在CSV中,我使用了 UTF-8作为StandardCharsets。

 //Convert Data to JSON:

   JSONArray jsonArray = new JSONArray();
   try {
       for (DataSnapshot d : dataSnapshot.getChildren()) {
           DoctorReports doctorReports = d.getValue(DoctorReports.class);
           Gson gson = new Gson();
           String response = gson.toJson(doctorReports);
             //String encoded = URLEncoder.encode(response, "ISO-8859-1");
            // response = URLDecoder.decode(encoded, "UTF-8");
           jsonArray.put(new JSONObject(response));
       }
       saveCsv(jsonArray);
   } catch (Exception e) {
       e.printStackTrace();

}

    // How I write to CSV File 
     CSVWriter writer = new CSVWriter(
           new OutputStreamWriter(new FileOutputStream(file), 
               StandardCharsets.UTF_8),
        CSVWriter.DEFAULT_SEPARATOR
       );
   String[][] arrayOfArrays = new String[outerArray.length()][];
   for (int i = 0; i < outerArray.length(); i++) {
       JSONObject innerJsonArray = (JSONObject) outerArray.get(i);
       String[] stringArray1 = new String[innerJsonArray.length()];
       stringArray1[0] = (String) innerJsonArray.getString("doctorName");
         stringArray1[1] = (String) innerJsonArray.getString("hospital");
         stringArray1[2] = (String) innerJsonArray.getString("specialty");
       arrayOfArrays[i] = stringArray1;
       writer.writeNext(arrayOfArrays[i]);
   }
   writer.close();

0 个答案:

没有答案