I'm having difficulty in getting JSON arrays and how exactly to target a specific array from a JSON response. i have to get all image url's from http://boilerpipe-web.appspot.com/extract?url=http%3A%2F%2Fwww.imdb.com%2Fmovies-in-theaters%2F%3Fref_%3Dnv_tp_inth_1&extractor=ArticleExtractor&output=json&extractImages=3&token=
so my resultant json should be like this,as i need only image src and alt for my application.
{
"images":
[{
"src":"https://images-na.ssl-images-amazon.com/images/M/MV5BMTQ5ODE4MTY2NV5BMl5BanBnXkFtZTgwMzM2NzEzMDI@._V1_UY209_C R0,0,140,209_AL_.jpg",
"alt":"Collateral Beauty (2016) Poster"
},
{
"src":"https://images-na.ssl-images-amazon.com/images/M/MV5BMjAwNDA1NjcwN15BMl5BanBnXkFtZTgwMDY0MDA2MDI@._V1_UY209_C R0,0,140,209_AL_.jpg",
"alt":"A Kind of Murder (2016) Poster"
},
{
"src":"https://images-na.ssl-images-amazon.com/images/M/MV5BMjA5MzgyNTIzMF5BMl5BanBnXkFtZTgwODg1OTY1MDI@._V1_UX140_C R0,0,140,209_AL_.jpg",
"alt":"Solace (2015) Poster"
},
{
"src":"https://images-na.ssl-images-amazon.com/images/M/MV5BOTg0Nzc1NjA0MV5BMl5BanBnXkFtZTgwNTcyNDQ0MDI@._V1_UX140_C R0,0,140,209_AL_.jpg",
"alt":"Fences (2016) Poster"
},
{
"src":"https://images-na.ssl-images-amazon.com/images/M/MV5BMTYxMjk0NDg4Ml5BMl5BanBnXkFtZTgwODcyNjA5OTE@._V1_UY209_CR0,0,140,209_AL_.jpg",
"alt":"Manchester by the Sea (2016) Poster"
},
{
"src":"https://images-na.ssl-images-amazon.com/images/M/MV5BMjI4MzU5NTExNF5BMl5BanBnXkFtZTgwNzY1MTEwMDI@._V1_UY209_CR0,0,140,209_AL_.jpg",
"alt":"Moana (2016) Poster"
}]
}
EDIT
After some guidence i made some changes and my code looks like this.
public class Main2Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
TextView output = (TextView) findViewById(R.id.textView1);
String strJson="http://boilerpipe-web.appspot.com/extract?url=http%3A%2F%2Fwww.imdb.com%2Fmovies-in-theaters%2F%3Fref_%3Dnv_tp_inth_1&extractor=KeepEverythingExtractor&output=img&extractImages=3&token=";
String data = "";
try {
try {
URL url=new URL(strJson);
HttpURLConnection httpURLConnection=(HttpURLConnection)url.openConnection();
httpURLConnection.connect();
httpURLConnection.setDoInput(true);
JSONObject jsonRootObject = new JSONObject(strJson);
JSONArray jsonArray = jsonRootObject.optJSONArray("images");
for(int i=0; i < jsonArray.length(); i++){
JSONObject jsonObject = jsonArray.getJSONObject(i);
String name = jsonObject.optString("alt").toString();
String image = jsonObject.optString("src").toString();
data += "Node"+i+" : \n Name= "+ name+" \n Image="+image;
}
output.setText(data);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (JSONException e) {e.printStackTrace();}
}
}
But still i am not able to get data from url i gave.