Value of type java.lang.String cannot be converted to JSONArray

The problem is that your JSON is in the incorrect format. I have tried with your sample JSON and found the solution to it. Now the inbuilt JSONObject and JSONArray cannot be used to get such a json response.

You need to add json-simple library to your project by adding it to gradle:

implementation 'com.googlecode.json-simple:json-simple:1.1.1'

Or download the library “json-simple-1.1.1.jar” from this link https://repo1.maven.org/maven2/com/googlecode/json-simple/json-simple/1.1.1/json-simple-1.1.1.jar

Then you can parse your JSON easily and it won’t give any error. I have made a small sample code for you on how to use it :

import org.json.simple.JSONArray;
import org.json.simple.parser.JSONParser;

JSONParser parser_obj = new JSONParser();
JSONArray array_obj = (JSONArray) parser_obj.parse("String from web service"); 
// in your case it will be "result" 

Then you can process it as per your need.

Leave a Comment