0
"papers": [ { "files": [ { "url": "http://farnsworth.papro.org.uk/file/977", "type": "Initial XML version of the paper", "name": "c6938201-dac0-4ef9-91cd-ca6e8c30f4b8.xml" }, { "url": "http://farnsworth.papro.org.uk/file/978", "type": "Final annotated XML file", "name": "c6938201-dac0-4ef9-91cd-ca6e8c30f4b8_final.xml" } ] 

How can i get the first url in this json file ? What I have so far is:

 JSONObject file = (JSONObject) files.get(j); String url = (String) file.get("url"); System.out.println(url); 
6
  • json.org/javadoc/org/json/JSONObject.html Commented Jun 15, 2013 at 23:50
  • Aside from "Don't use that ancient crufty json.org library" there are numerous examples of parsing JSON in Java here on SO that would get you further than you are. Commented Jun 15, 2013 at 23:52
  • stackoverflow.com/questions/7332611/… ... stackoverflow.com/questions/8939250/parsing-json-file-java?lq=1 would also be of interest. Commented Jun 15, 2013 at 23:55
  • currently am getting the two url but i can't figure out how to get just the first url in the file. I don't know if there is something like .first()? Commented Jun 15, 2013 at 23:56
  • I have carefully examine all this links before posting this question, but none seems to have an answer to my question. Commented Jun 16, 2013 at 0:00

1 Answer 1

1

something like this should work :

JSONArray results = d.getJSONArray("files"); JSONObject p = (JSONObject)results.get(0); url = p.getString("url"); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.