 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert JSON Array to normal Java Array?
The get method of the JSONArray class returns the element at a particular index. Using this method, you can get the elements of the JSONArray object and populate the array with them.
Example
import java.util.Arrays; import org.json.JSONArray; public class JsonToArray {    public static void main(String args[]) throws Exception {       String [] myArray = {"JavaFX", "HBase", "JOGL", "WebGL"};       JSONArray jsArray = new JSONArray();       for (int i = 0; i < myArray.length; i++) {          jsArray.put(myArray[i]);      }      System.out.println(jsArray);      String[] array = new String[myArray.length];      for (int i = 0; i < myArray.length; i++) {         array[i] = (String)jsArray.get(i);      }      System.out.println("Contents of the array :: "+Arrays.toString(array));    } }  Output
["JavaFX","HBase","JOGL","WebGL"] Contents of the array :: [JavaFX, HBase, JOGL, WebGL]
Advertisements
 