I'm trying to get the data that comes from these link
link
link
I have tried many methods but in the end I always get an error when going through this line JSONObject jsonObj = new JSONObject(json);
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("http://15.26.54.26/swapi/api/data/xml")
.build();
Response responses = null;
try {
responses = client.newCall(request).execute();
json = responses.body().string();
System.out.println("JSON: " + json);
try {
JSONObject jsonObj = new JSONObject(json);
// JSONObject obj = new JSONObject(jsonObj);
// Getting JSON Array node
JSONArray contacts = jsonObj.getJSONArray("Carro");
for (int i = 0; i < contacts.length(); i++) {
JSONObject c = contacts.getJSONObject(i);
String id = c.getString("idintelisis");
System.out.println("TESTEEEEEEEEEEEEEEEEEEEEEEE: " + id);
}
} catch (JSONException ex) {
System.out.println("Errrrrrrrrrrrrrrrrrrrrrrrrorrrrrrrrrrrrrrrrrrr: " + ex);
}
} catch (IOException e) {
e.printStackTrace();
}
This is the long error that launches when that line bursts
01-11 10: 04: 47.487 6541-7024 / pa.com.tropigas.pedidostf W / System.err: org.json.JSONException: Value [{"idintelisis": 101, "observations": "Nitin" , "date": null, "car": null, "cargapkt": "sd5"}, {"idintelisis": 101, "observations": "Nitin", "date": null, "car": null, " loadpkt ":" sd5 "}] of type java.lang.String can not be converted to JSONObject 01-11 10: 04: 47.487 6541-7024 / pa.com.tropigas.pedidostf W / System.err: at org.json.JSON.typeMismatch (JSON.java) 01-11 10: 04: 47.487 6541-7024 / pa.com.tropigas.pedidostf W / System.err: at org.json.JSONObject. (JSONObject.java) 01-11 10: 04: 47.487 6541-7024 / pa.com.tropigas.pedidostf W / System.err: at org.json.JSONObject. (JSONObject.java) 01-11 10: 04: 47.487 6541-7024 / pa.com.tropigas.pedidostf W / System.err: at pa.com.tropigas.pedidostf.CarrosActivity $ POST.doInBackground (CarrosActivity.java:114) 01-11 10: 04: 47.487 6541-7024 / pa.com.tropigas.pedidostf W / System.err: at pa.com.tropigas.pedidostf.CarrosActivity $ POST.doInBackground (CarrosActivity.java:65) 01-11 10: 04: 47.487 6541-7024 / pa.com.tropigas.pedidostf W / System.err: at android.os.AsyncTask $ 2.call (AsyncTask.java) 01-11 10: 04: 47.487 6541-7024 / pa.com.tropigas.pedidostf W / System.err: at java.util.concurrent.FutureTask.run (FutureTask.java) 01-11 10: 04: 47.487 6541-7024 / pa.com.tropigas.pedidostf W / System.err: at android.os.AsyncTask $ SerialExecutor $ 1.run (AsyncTask.java) 01-11 10: 04: 47.487 6541-7024 / pa.com.tropigas.pedidostf W / System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java) 01-11 10: 04: 47.487 6541-7024 / pa.com.tropigas.pedidostf W / System.err: at java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java) 01-11 10: 04: 47.487 6541-7024 / pa.com.tropigas.pedidostf W / System.err: at java.lang.Thread.run (Thread.java) 01-11 10: 04: 47.487 6541-7024 / pa.com.tropigas.pedidostf I / System.out: Error: org.json.JSONException: Value [{"idintelisis": 101, "observations": "Nitin", "date": null, "car": null, "cargapkt": "sd5"}, {"idintelisis": 101, "observations": "Nitin", "date": null, "car": null, "cargapkt ":" sd5 "}] of type java.lang.String can not be converted to JSONObject
I've used Postman to review the result of Json and also the Json of the log and everything indicates that the Json is correct in terms of structure I do not understand why it breaks when trying to convert it to an object of Json