0

the string I have into "jsonString" is the content of this link: http://85.18.173.82/cineca/wp5/json/events.json

Now I want the value "Day" of the second "Event".

JSONObject o = new JSONObject(jsonString);
String day = o.getString("XXXXXXXXXX");
System.out.println(day);

What does I have to put as argument of o.getString?

Many thanks

1
  • you really should post the json in your question instead of just posting an external link to it. Commented Oct 15, 2013 at 15:01

2 Answers 2

2
JSONObject obj = new JSONObject(json);

JSONArray array = obj.getJSONArray("Events");
for(int i = 0 ; i < array.length() ; i++){
    System.out.println(array.getJSONObject(i).getJSONObject("Event").getString("Day"));
}

In this way, you can access, thanks.

Sign up to request clarification or add additional context in comments.

Comments

1

The way you're constructing your JSONObject is wrong. By using this constructor you're not reading the json from that URL, you're actually using that string as a json representation (which it is not).

If you want to first read the json from your URL you'll have to do an HTTP GET request and then construct a JSONObject out of the response.

For more info, take a look at JSONObject docs

1 Comment

Thanks for your answer, I have already done the HTTP request, now I have the content of the file in a string called jsonString.

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.