Here you get JSONObject so change this line:

JSONArray jsonArray = new JSONArray(readlocationFeed); 

with following:

JSONObject jsnobject = new JSONObject(readlocationFeed);

and after

JSONArray jsonArray = jsnobject.getJSONArray("locations");
for (int i = 0; i < jsonArray.length(); i++) {
    JSONObject explrObject = jsonArray.getJSONObject(i);
}
Answer from kyogs on Stack Overflow
🌐
W3Schools
w3schools.com › js › js_json_arrays.asp
W3Schools.com
In JSON, array values must be of type string, number, object, array, boolean or null. In JavaScript, array values can be all of the above, plus any other valid JavaScript expression, including functions, dates, and undefined. You can create a JavaScript array from a literal: myArray = ["Ford", "BMW", "Fiat"]; Try it Yourself » ·
Discussions

java - How do I create a JSONArray from this string? - Stack Overflow
If you are using Gson, why would you want a JSONArray? I would use Gson to parse that back into List>. More on stackoverflow.com
🌐 stackoverflow.com
February 11, 2016
How do I create a JSON string from an Array?
Hello, So I see plenty of examples on how to take an JSON string the bot got from another service and deserialize it into an array for it to process. But I’m trying to go in the other direction. My bot has gathered various bits of information into an array and I want to encode that into a ... More on forum.uipath.com
🌐 forum.uipath.com
0
0
July 30, 2018
java - Can't Convert string to JsonArray - Stack Overflow
Is this the way to convert this Collections string to JSonArray? More on stackoverflow.com
🌐 stackoverflow.com
json - Android - how to parse JsonArray from string? - Stack Overflow
What I want to ask here is: how to parse the array from json string. Sorry for my limited English Skill 2013-01-28T16:41:41.863Z+00:00 ... Check my edits to the answer, I think I made it a bit clearer. 2013-01-28T16:43:09.313Z+00:00 ... Basically, your main problem comes down to the fact that you CANNOT initialize a JSONArray with a string. You must first create ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Stleary
stleary.github.io › JSON-java › org › json › JSONArray.html
JSONArray
A String value. ... Append a boolean value. This increases the array's length by one. ... Put a value in the JSONArray, where the value will be a JSONArray which is produced from a Collection.
🌐
UiPath Community
forum.uipath.com › learning hub › academy feedback
How do I create a JSON string from an Array? - Academy Feedback - UiPath Community Forum
Hello, So I see plenty of examples on how to take an JSON string the bot got from another service and deserialize it into an array for it to process. But I’m trying to go in the other direction. My bot has gathered various bits of information into an array and I want to encode that into a ...
Published   July 30, 2018
🌐
IBM
ibm.com › support › pages › creating-json-string-json-object-and-json-arrays-automation-scripts
Creating a JSON String from JSON Object and JSON Arrays in Automation Scripts
# creating a JSON String with an array (directly executed via Run Automation Script button) from com.ibm.json.java import JSONObject, JSONArray from sys import * # method for creating a JSON formatted String including an array within def createJSONstring(): # defining the first child object ch1_obj = JSONObject() ch1_obj.put('CH_FIELD_1', 1) ch1_obj.put('CH_FIELD_2', 'VALUE_2') # defining the second child object ch2_obj = JSONObject() ch2_obj.put('CH_FIELD_1', 2) ch2_obj.put('CH_FIELD_2', 'VALUE_3') # adding child objects to children array ch_arr = JSONArray() ch_arr.add(ch1_obj) ch_arr.add(ch
🌐
Oracle
docs.oracle.com › javaee › 7 › api › javax › json › JsonArray.html
JsonArray (Java(TM) EE 7 Specification APIs)
A JsonArray object can be created by reading JSON data from an input source or it can be built from scratch using an array builder object.
🌐
FlutterFlow Community
community.flutterflow.io › ask-the-community › post › create-json-array-from-list-of-strings-1A4EOYJN1pEDzRa
Create JSON array from list of strings?
April 22, 2024 - Hi all curious, I'm trying to collect a list of emails from my user collection and send that list as a JSON array in an API request. Is it possible to create a JSON array in FF for this? Hardcoding values such as this works fine with a test.
Find elsewhere
Top answer
1 of 3
47

To have a string value inside your JSON array, you must remember to backslash escape your double-quotes in your Java program. See the declaration of s below.

String s = "[[\"110917       \", 3.0099999999999998, -0.72999999999999998, 2.8500000000000001, 2.96, 685.0, 38603.0], [\"110917    \", 2.71, 0.20999999999999999, 2.8199999999999998, 2.8999999999999999, 2987.0, 33762.0]]";

Your code in the main() method works fine. Below is just a minor modification of your code in the main() method.

System.out.println("String to Json Array Stmt");
JsonParser parser = new JsonParser();
JsonElement tradeElement = parser.parse(s);
JsonArray trade = tradeElement.getAsJsonArray();
System.out.println(trade);

Lastly, remember to prefix your statement "com.google.gson.*" with the keyword "import", as shown below.

import com.google.gson.*;
2 of 3
11

I don't see the problem. This code runs fine for me:

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;


public class GsonExample {
    public static void main(String[] args) {
        String s= "[[\"110917\", 3.0099999999999998, -0.72999999999999998," +
                "2.8500000000000001, 2.96, 685.0, 38603.0], [\"110917\", 2.71," +
                "0.20999999999999999, 2.8199999999999998, 2.8999999999999999," +
                "2987.0, 33762.0]]";


        JsonParser  parser = new JsonParser();
        JsonElement elem   = parser.parse( s );

        JsonArray elemArr = elem.getAsJsonArray();
        System.out.println( elemArr );
    }
}

The only problem maybe is that you failed to properly escape the double quotes in your s string literal.

Top answer
1 of 3
18

This is how to initialize a JSON parser:

JSONObject jsonObject = new JSONObject(jsonString);

That will give you the entire string as a Json Object. From there, pull out an individual array as a JsonArray, like this:

JSONArray jsonArray = jsonObject.getJSONArray("LotPrizes");

To access each "LotPrizes" you can use for loop logic:

for(int i=0;i<jsonArray.length();i++)
{
  JSONObject curr = jsonArray.getJSONObject(i);

  prize = curr.getString("Prize")

//Do stuff with the Prize String here
//Add it to a list, print it out, etc.
}

EDIT: Final code after your JSON edit:

JSONArray jsonArray = null;
String jsonString = <your string>
String currPrize = null;

JSONObject jsonObject = new JSONObject(jsonString);

jsonArray = jsonObject.getJSONArray("data");

for(int i=0;i<jsonArray.length();i++)
{
    JSONArray currLot = jsonArray.getJSONObject(i);

    for(int j=0; j<currLot.length();j++)
    {
        JSONobject curr = currLot.getJSONObject(j);

        currPrize = curr.getString("Prize");

        //Do something with Prize
    }
}

This code is functional and I'm using an almost identical version in my code. Hope this (finally) works for you.

2 of 3
2

You can retrieve the jsondata from your string as follows ..

            JSONObject json = new JSONObject(jsonString);
            JSONArray jData = json.getJSONArray("data");
            for (int i = 0; i < jData.length(); i++) {
                JSONObject jo = jData.getJSONObject(i);

                JSONArray jLotPrizes = jo.getJSONArray("LotPrizes");
                for (int j = 0; j < jLotPrizes.length(); j++) {
                    JSONObject jobj = jLotPrizes.getJSONObject(j);

                    Log.i("Prize", "" + jobj.getString("Prize"));
                    Log.i("Range", "" + jobj.getString("Range"));
                }

            }
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-convert-json-array-to-string-array-in-java
How to Convert JSON Array to String Array in Java? - GeeksforGeeks
July 23, 2025 - Here, we will use some example data to input into the array, but you can use the data as per your requirements. 1. Defining the array · JSONArray exampleArray = new JSONArray(); Note that we will import the org.json package in order to use ...
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › json array of strings
JSON Array of Strings | How JSON Array of String Works? (Examples)
April 14, 2023 - Guide to JSON Array of Strings. Here we also discuss how json array of string works? along with examples and its code implementation.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Couchbase
docs.couchbase.com › sdk-api › couchbase-java-client › com › couchbase › client › java › json › JsonArray.html
JsonArray (Couchbase Java SDK 3.11.1 API)
Static method to create a JsonArray from a JSON String. Not to be confused with from(Object...) from(aString)} which will populate a new array with the string. The string is expected to be a valid JSON array representation (eg.
🌐
Processing
processing.github.io › processing-javadocs › core › processing › data › JSONArray.html
JSONArray
Put or replace a String value. If the index is greater than the length of the JSONArray, then null elements will be added as necessary to pad it out.
🌐
Tabnine
tabnine.com › home page › code › java › org.json.jsonarray
org.json.JSONArray java code examples | Tabnine
public String creatingJsonString() { JSONArray pets = new JSONArray(); pets.put("cat"); pets.put("dog"); JSONObject person = new JSONObject(); person.put("name", "John Brown"); person.put("age", 35); person.put("pets", pets); return ...
🌐
Google
developers.google.com › j2objc › jsonarray
JSONArray | J2ObjC | Google for Developers
July 10, 2024 - Creates a new JSONArray with values from the JSON string.
🌐
Baeldung
baeldung.com › home › json › introduction to json-java (org.json)
Introduction to JSON-Java | Baeldung
June 20, 2025 - JSONTokener – a tool that breaks a piece of text into a series of tokens that can be used by JSONObject or JSONArray to parse JSON strings · CDL – a tool that provides methods to convert comma-delimited text into a JSONArray and vice versa · Cookie – converts from JSON String to cookies and vice versa