1

1) I've got a JSON file:

{
  "serverURI":"http://localhost:8080/PocketUNI_API/serverURLs",
  "newsURI":"http://localhost:8080/gateway/rss/rss.xml",
  "modulesURI":"http://localhost:8080/PocketUNI_API/modules"
}

2) I need to get URLs on Java client in String format.

String json = jsonReceiver.makeHttpRequest(URL_SERVER, "GET", params);
JSONArray uris = new JSONArray(json);

Receiver works fine and json shows the correct string received, but when it goes to parsing with JSONArray it throws an error

org.json.JSONException: Value {"serverURI":"http:\/\/192.168.0.... of type org.json.JSONObject cannot be converted to JSONArray. 

Question: How to parse json with URL values?

exomen
  • 355
  • 2
  • 6
  • 20

4 Answers4

1

You don't get a JSONArray but a JSONObject.

JSONObject uris = new JSONObject(json);
1

json is a json object not an array, that is why you are getting the error. An array will be wrapped with in [ and ], and objects within { and }.

JSONObject uris = new JSONObject (json);
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

Instead of JSONArray you must use JSONObject.

JSONObject uris = new JSONObject(json);
Jeyvison
  • 190
  • 1
  • 14
0

In your code just replace JSONArray to JSONobject

JSONObject uris = new JSONObject(json);
Vivek Bajpai
  • 1,617
  • 1
  • 19
  • 35