Saturday, 16 March 2019

Convert JSONArray to comma separated string


CDL.rowToString(jsonArray) method returns a comma separated string from JSONArray.

JSONArray jsonArray = new JSONArray();
jsonArray.put("Chess");
jsonArray.put("Tennis");
jsonArray.put("Cricket");
jsonArray.put("Football");

String str = CDL.rowToString(jsonArray);

App.java
package com.sample;

import org.json.CDL;
import org.json.JSONArray;

public class App {

 public static void main(String args[]) {
  JSONArray jsonArray = new JSONArray();
  jsonArray.put("Chess");
  jsonArray.put("Tennis");
  jsonArray.put("Cricket");
  jsonArray.put("Football");
  
  String str = CDL.rowToString(jsonArray);

  System.out.println(str);

 }
}

Output
Chess,Tennis,Cricket,Football



Previous                                                 Next                                                 Home

No comments:

Post a Comment