This code should work:
JSONObject jsonObject = (JSONObject) obj;
JSONArray msg = (JSONArray) jsonObject.get("items");
Iterator iterator = msg.iterator();
while (iterator.hasNext()) {
//System.out.println(iterator.next());
JSONObject item = (JSONObject) iterator.next();
JSONObject item_snippet = (JSONObject) item.get("snippet");
System.out.println( item_snippet.get("title"));
}
You have a JSONObject at the root of your JSON string. In it, there's an JSONArray named items
. From it you have to pull out individual items in while loop.
For each item there's JSONObject snippet
nested in. Finally you'll find your title
string in it.