Saturday, 16 March 2019

Convert comma separated string to JSONArray


‘CDL.rowToJSONArray’ is used to convert comma separated string to JSONArray.

Example
String hobbies = "Chess,Tennis,Cricket,Footbal";
JSONArray jsonArray = CDL.rowToJSONArray(new JSONTokener(hobbies));

App.java
package com.sample;

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

public class App {

 public static void main(String args[]) {
  String hobbies = "Chess,Tennis,Cricket,Footbal";

  
  JSONArray jsonArray = CDL.rowToJSONArray(new JSONTokener(hobbies));
 

  System.out.println(jsonArray);

 }
}

Output
["Chess","Tennis","Cricket","Footbal"]



Previous                                                 Next                                                 Home

No comments:

Post a Comment