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?

4
  • why are you trying to convert Object to Array ? Commented Apr 9, 2013 at 14:15
  • to loop through the multiple json objects using jsonArray object Commented Apr 9, 2013 at 14:20
  • the code you posted above dosnt seems to have an array of jsonobject instead it has a single json object and casting obejct to array will give u jsonexception try to extract a single object Commented Apr 9, 2013 at 14:23
  • not JSONArray but JSONObject. JSONObject json = new JSONObject(str) Commented Apr 9, 2013 at 14:30

4 Answers 4

1

You don't get a JSONArray but a JSONObject.

JSONObject uris = new JSONObject(json);
Sign up to request clarification or add additional context in comments.

Comments

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);

1 Comment

Thanks a lot that helps!:) Sorry that can't make thumb up, not enough reputation.
0

Instead of JSONArray you must use JSONObject.

JSONObject uris = new JSONObject(json);

Comments

0

In your code just replace JSONArray to JSONobject

JSONObject uris = new JSONObject(json);

1 Comment

Thanks a lot that helps!:) Sorry that can't make thumb up, not enough reputation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.