Q:

Cant find value to a JSON query in android

The JSON, i have looks like this
{"cod":"200","message":0.0148,"cnt":36,"list":[{"dt":1498910400,"main":{"temp":298.35,"temp_min":298.35,"temp_max":302.449,"pressure":982.24,"sea_level":1007.89,"grnd_level":982.24,"humidity":100,"temp_kf":-4.1},"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"clouds":{"all":8},"wind":{"speed":2.87,"deg":150.001},"rain":{"3h":3.1},"sys":{"pod":"d"},"dt_txt":"2017-07-01 12:00:00"},{"dt":1498921200,"main":{"temp":297.76,"temp_min":297.76,"temp_max":300.835,"pressure":983.35,"sea_level":1009.22,"grnd_level":983.35,"humidity":91,"temp_kf":-3.07},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10n"}],"clouds":{"all":0},"wind":{"speed":1.37,"deg":83.5017},"rain":{"3h":0.875},"sys":{"pod":"n"},"dt_txt":"2017-07-01 15:00:00"},{"dt":1498932000,"main":{"temp":298.38,"temp_min":298.38,"temp_max":300.431,"pressure":984.83,"sea_level":1010.78,"grnd_level":984.83,"humidity":89,"temp_kf":-2.05},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"clouds":{"all":20},"wind":{"speed":2.68,"deg":129.002},"rain":{},"sys":{"pod":"n"},"dt_txt":"2017-07-01 18:00:00"},{"dt":1498942800,"main":{"temp":298.75,"temp_min":298.75,"temp_max":299.775,"pressure":984.26,"sea_level":1010.27,"grnd_level":984.26,"humidity":94,"temp_kf":-1.02},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":68},"wind":{"speed":3.56,"deg":143.004},"rain":{},"sys":{"pod":"n"},"dt_txt":"2017-07-01 21:00:00"},{"dt":1498953600,"main":{"temp":297.455,"temp_min":297.455,"temp_max":297.455,"pressure":984.25,"sea_level":1010.25,"grnd_level":984.25,"humidity":98,"temp_kf":0},"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"clouds":{"all":80},"wind":{"speed":3.77,"deg":83.5007},"rain":{"3h":6.47},"sys":{"pod":"d"},"dt_txt":"2017-07-02 00:00:00"},{"dt":1498964400,"main":{"temp":298.488,"temp_min":298.488,"temp_max":298.488,"pressure":985.43,"sea_level":1011.49,"grnd_level":985.43,"humidity":97,"temp_kf":0},"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"clouds":{"all":92},"wind":{"speed":3.41,"deg":81.5022},"rain":{"3h":3.67},"sys":{"pod":"d"},"dt_txt":"2017-07-02 03:00:00"},{"dt":1498975200,"main":{"temp":301.011,"temp_min":301.011,"temp_max":301.011,"pressure":986,"sea_level":1011.94,"grnd_level":986,"humidity":94,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":48},"wind":{"speed":3.06,"deg":72.0091},"rain":{"3h":2.74},"sys":{"pod":"d"},"dt_txt":"2017-07-02 06:00:00"},{"dt":1498986000,"main":{"temp":304.782,"temp_min":304.782,"temp_max":304.782,"pressure":984.14,"sea_level":1009.97,"grnd_level":984.14,"humidity":92,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":12},"wind":{"speed":1.96,"deg":70.002},"rain":{"3h":0.0050000000000026},"sys":{"pod":"d"},"dt_txt":"2017-07-02 09:00:00"},{"dt":1498996800,"main":{"temp":305.489,"temp_min":305.489,"temp_max":305.489,"pressure":983.04,"sea_level":1008.88,"grnd_level":983.04,"humidity":83,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":2.06,"deg":100.004},"rain":{},"sys":{"pod":"d"},"dt_txt":"2017-07-02 12:00:00"},{"dt":1499007600,"main":{"temp":300.15,"temp_min":300.15,"temp_max":300.15,"pressure":985.43,"sea_level":1011.22,"grnd_level":985.43,"humidity":100,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10n"}],"clouds":{"all":20},"wind":{"speed":5.97,"deg":142.003},"rain":{"3h":2.35},"sys":{"pod":"n"},"dt_txt":"2017-07-02 15:00:00"},{"dt":1499018400,"main":{"temp":299.443,"temp_min":299.443,"temp_max":299.443,"pressure":986.75,"sea_level":1012.83,"grnd_level":986.75,"humidity":92,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10n"}],"clouds":{"all":32},"wind":{"speed":2.67,"deg":146.008},"rain":{"3h":2.03},"sys":{"pod":"n"},"dt_txt":"2017-07-02 18:00:00"},{"dt":1499029200,"main":{"temp":298.712,"temp_min":298.712,"temp_max":298.712,"pressure":986.4,"sea_level":1012.45,"grnd_level":986.4,"humidity":97,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":32},"wind":{"speed":1.94,"deg":127.5},"rain":{},"sys":{"pod":"n"},"dt_txt":"2017-07-02 21:00:00"},{"dt":1499040000,"main":{"temp":298.021,"temp_min":298.021,"temp_max":298.021,"pressure":986.11,"sea_level":1012.18,"grnd_level":986.11,"humidity":97,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":36},"wind":{"speed":1.43,"deg":112.501},"rain":{},"sys":{"pod":"d"},"dt_txt":"2017-07-03 00:00:00"},{"dt":1499050800,"main":{"temp":300.755,"temp_min":300.755,"temp_max":300.755,"pressure":987.29,"sea_level":1013.25,"grnd_level":987.29,"humidity":98,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":88},"wind":{"speed":2.07,"deg":61.0003},"rain":{"3h":0.055},"sys":{"pod":"d"},"dt_txt":"2017-07-03 03:00:00"},{"dt":1499061600,"main":{"temp":300.945,"temp_min":300.945,"temp_max":300.945,"pressure":987.7,"sea_level":1013.52,"grnd_level":987.7,"humidity":100,"temp_kf":0},"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"clouds":{"all":80},"wind":{"speed":1.7,"deg":60.0011},"rain":{"3h":4.55},"sys":{"pod":"d"},"dt_txt":"2017-07-03 06:00:00"},{"dt":1499072400,"main":{"temp":303.41,"temp_min":303.41,"temp_max":303.41,"pressure":986.36,"sea_level":1012.17,"grnd_level":986.36,"humidity":96,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":0},"wind":{"speed":4.57,"deg":132},"rain":{"3h":1.83},"sys":{"pod":"d"},"dt_txt":"2017-07-03 09:00:00"},{"dt":1499083200,"main":{"temp":302.802,"temp_min":302.802,"temp_max":302.802,"pressure":985.84,"sea_level":1011.72,"grnd_level":985.84,"humidity":78,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":0},"wind":{"speed":5.02,"deg":117.002},"rain":{"3h":0.3},"sys":{"pod":"d"},"dt_txt":"2017-07-03 12:00:00"},{"dt":1499094000,"main":{"temp":298.588,"temp_min":298.588,"temp_max":298.588,"pressure":987.1,"sea_level":1013.14,"grnd_level":987.1,"humidity":89,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":4.01,"deg":134.502},"rain":{},"sys":{"pod":"n"},"dt_txt":"2017-07-03 15:00:00"},{"dt":1499104800,"main":{"temp":297.28,"temp_min":297.28,"temp_max":297.28,"pressure":988.06,"sea_level":1014.15,"grnd_level":988.06,"humidity":93,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":2.06,"deg":139.003},"rain":{},"sys":{"pod":"n"},"dt_txt":"2017-07-03 18:00:00"},{"dt":1499115600,"main":{"temp":296.603,"temp_min":296.603,"temp_max":296.603,"pressure":987.17,"sea_level":1013.28,"grnd_level":987.17,"humidity":95,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":32},"wind":{"speed":1.37,"deg":25.0045},"rain":{},"sys":{"pod":"n"},"dt_txt":"2017-07-03 21:00:00"},{"dt":1499126400,"main":{"temp":297.26,"temp_min":297.26,"temp_max":297.26,"pressure":986.48,"sea_level":1012.58,"grnd_level":986.48,"humidity":92,"temp_kf":0},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"clouds":{"all":24},"wind":{"speed":1.36,"deg":20.0017},"rain":{},"sys":{"pod":"d"},"dt_txt":"2017-07-04 00:00:00"},{"dt":1499137200,"main":{"temp":301.786,"temp_min":301.786,"temp_max":301.786,"pressure":987.49,"sea_level":1013.44,"grnd_level":987.49,"humidity":93,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"02d"}],"clouds":{"all":8},"wind":{"speed":2.01,"deg":36.0015},"rain":{},"sys":{"pod":"d"},"dt_txt":"2017-07-04 03:00:00"},{"dt":1499148000,"main":{"temp":304.808,"temp_min":304.808,"temp_max":304.808,"pressure":987.26,"sea_level":1013.16,"grnd_level":987.26,"humidity":85,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":44},"wind":{"speed":2.1,"deg":71.0025},"rain":{},"sys":{"pod":"d"},"dt_txt":"2017-07-04 06:00:00"},{"dt":1499158800,"main":{"temp":307.06,"temp_min":307.06,"temp_max":307.06,"pressure":985.48,"sea_level":1011.23,"grnd_level":985.48,"humidity":79,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":1.42,"deg":24.0024},"rain":{},"sys":{"pod":"d"},"dt_txt":"2017-07-04 09:00:00"},{"dt":1499169600,"main":{"temp":307.369,"temp_min":307.369,"temp_max":307.369,"pressure":984.53,"sea_level":1010.23,"grnd_level":984.53,"humidity":69,"temp_kf":0},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"clouds":{"all":12},"wind":{"speed":1.98,"deg":358.001},"rain":{},"sys":{"pod":"d"},"dt_txt":"2017-07-04 12:00:00"},{"dt":1499180400,"main":{"temp":303.26,"temp_min":303.26,"temp_max":303.26,"pressure":985.44,"sea_level":1011.36,"grnd_level":985.44,"humidity":76,"temp_kf":0},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"clouds":{"all":12},"wind":{"speed":1.22,"deg":29.0038},"rain":{},"sys":{"pod":"n"},"dt_txt":"2017-07-04 15:00:00"},{"dt":1499191200,"main":{"temp":301.15,"temp_min":301.15,"temp_max":301.15,"pressure":986.61,"sea_level":1012.56,"grnd_level":986.61,"humidity":80,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":1.4,"deg":109.002},"rain":{},"sys":{"pod":"n"},"dt_txt":"2017-07-04 18:00:00"},{"dt":1499202000,"main":{"temp":299.73,"temp_min":299.73,"temp_max":299.73,"pressure":986.1,"sea_level":1012.07,"grnd_level":986.1,"humidity":87,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":1.95,"deg":177.002},"rain":{},"sys":{"pod":"n"},"dt_txt":"2017-07-04 21:00:00"},{"dt":1499212800,"main":{"temp":298.704,"temp_min":298.704,"temp_max":298.704,"pressure":985.81,"sea_level":1011.83,"grnd_level":985.81,"humidity":92,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":1.36,"deg":92.001},"rain":{},"sys":{"pod":"d"},"dt_txt":"2017-07-05 00:00:00"},{"dt":1499223600,"main":{"temp":303.762,"temp_min":303.762,"temp_max":303.762,"pressure":987.2,"sea_level":1013.15,"grnd_level":987.2,"humidity":90,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":2.06,"deg":117.006},"rain":{},"sys":{"pod":"d"},"dt_txt":"2017-07-05 03:00:00"},{"dt":1499234400,"main":{"temp":307.139,"temp_min":307.139,"temp_max":307.139,"pressure":986.96,"sea_level":1012.8,"grnd_level":986.96,"humidity":83,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":0},"wind":{"speed":1.97,"deg":206.504},"rain":{"3h":0.030000000000001},"sys":{"pod":"d"},"dt_txt":"2017-07-05 06:00:00"},{"dt":1499245200,"main":{"temp":308.369,"temp_min":308.369,"temp_max":308.369,"pressure":985.01,"sea_level":1010.67,"grnd_level":985.01,"humidity":75,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":12},"wind":{"speed":0.9,"deg":325.5},"rain":{"3h":0.3},"sys":{"pod":"d"},"dt_txt":"2017-07-05 09:00:00"},{"dt":1499256000,"main":{"temp":307.311,"temp_min":307.311,"temp_max":307.311,"pressure":984.21,"sea_level":1010,"grnd_level":984.21,"humidity":69,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":56},"wind":{"speed":1.66,"deg":136.508},"rain":{"3h":0.020000000000003},"sys":{"pod":"d"},"dt_txt":"2017-07-05 12:00:00"},{"dt":1499266800,"main":{"temp":304.306,"temp_min":304.306,"temp_max":304.306,"pressure":985.56,"sea_level":1011.7,"grnd_level":985.56,"humidity":73,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10n"}],"clouds":{"all":24},"wind":{"speed":0.9,"deg":55.502},"rain":{"3h":1.21},"sys":{"pod":"n"},"dt_txt":"2017-07-05 15:00:00"},{"dt":1499277600,"main":{"temp":301.405,"temp_min":301.405,"temp_max":301.405,"pressure":986.85,"sea_level":1012.92,"grnd_level":986.85,"humidity":79,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10n"}],"clouds":{"all":8},"wind":{"speed":2.1,"deg":136.001},"rain":{"3h":0.11},"sys":{"pod":"n"},"dt_txt":"2017-07-05 18:00:00"},{"dt":1499288400,"main":{"temp":300.897,"temp_min":300.897,"temp_max":300.897,"pressure":986.29,"sea_level":1012.45,"grnd_level":986.29,"humidity":87,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":3.32,"deg":148},"rain":{},"sys":{"pod":"n"},"dt_txt":"2017-07-05 21:00:00"}],"city":{"id":1264728,"name":"Ludhiana","coord":{"lat":30.9,"lon":75.85},"country":"IN"}}

I was trying to make a simple weather app, but while trying to find weather parameter, it always outputs as the value for weather not found.
Here's the Android Code
     package com.example.nishantsaini.guessthecelebapp;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}
public void weatherInfo(View view){
    EditText text = (EditText) findViewById(R.id.editText);
    Editable mes = text.getText();

    DownloadTask downloadTask = new DownloadTask();
    downloadTask.execute("http://api.openweathermap.org/data/2.5/forecast?q="+ mes +"&APPID=0ca89628e66d02d2d7da9049a55155ac");

}

public class DownloadTask extends AsyncTask<String, Void, String>{
    @Override
    protected String doInBackground(String... strings) {
        URL url;

        String result = "";
        HttpURLConnection connection;
        try {

            url =new URL(strings[0]);
            connection = (HttpURLConnection) url.openConnection();
            InputStream in = connection.getInputStream();
            InputStreamReader reader = new InputStreamReader(in);
            int data = reader.read();
            while (data != -1){
                char current = (char) data;
                result += current;
                data = reader.read();
            }
            return result;

        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage();

        }
    }
    @Override
    protected void onPostExecute(String result){
        super.onPostExecute(result);

        try {

            Log.i("Contents",result);
            JSONObject object = new JSONObject(result);
            String mes = object.getString("weather");
            Log.i("Weather content",mes);

            JSONArray arr = new JSONArray(mes);
            for (int i = 0; i <arr.length() ; i++) {
                JSONObject jsonpart = arr.getJSONObject(i);
                Log.i("Main",jsonpart.getString("main"));
                Log.i("Description",jsonpart.getString("description"));

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

}

Here's the stack tree
07-01 17:21:05.191 9836-9836/com.example.nishantsaini.guessthecelebapp 
W/System.err: org.json.JSONException: No value for weather
07-01 17:21:05.191 9836-9836/com.example.nishantsaini.guessthecelebapp 
W/System.err:     at org.json.JSONObject.get(JSONObject.java:392)
07-01 17:21:05.191 9836-9836/com.example.nishantsaini.guessthecelebapp 
W/System.err:     at org.json.JSONObject.getString(JSONObject.java:553)
07-01 17:21:05.192 9836-9836/com.example.nishantsaini.guessthecelebapp 
W/System.err:     at 
com.example.nishantsaini.guessthecelebapp.
MainActivity$DownloadTask.onPostExecute(MainActivity.java:77)
07-01 17:21:05.193 9836-9836/com.example.nishantsaini.guessthecelebapp 
W/System.err:at com.example.nishantsaini.guessthecelebapp.
MainActivity$DownloadTask.onPostExecute(MainActivity.java:42)
07-01 17:21:05.193 9836-9836/com.example.nishantsaini.guessthecelebapp 
W/System.err:     at android.os.AsyncTask.finish(AsyncTask.java:667)
07-01 17:21:05.193 9836-9836/com.example.nishantsaini.guessthecelebapp 
W/System.err:     at android.os.AsyncTask.-wrap1(Unknown Source:0)
07-01 17:21:05.193 9836-9836/com.example.nishantsaini.guessthecelebapp 
W/System.err:     at 
android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684)
07-01 17:21:05.193 9836-9836/com.example.nishantsaini.guessthecelebapp 
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:105)
07-01 17:21:05.193 9836-9836/com.example.nishantsaini.guessthecelebapp 
W/System.err:     at android.os.Looper.loop(Looper.java:164)
07-01 17:21:05.194 9836-9836/com.example.nishantsaini.guessthecelebapp 
W/System.err:     at 
android.app.ActivityThread.main(ActivityThread.java:6540)
07-01 17:21:05.194 9836-9836/com.example.nishantsaini.guessthecelebapp 
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
07-01 17:21:05.194 9836-9836/com.example.nishantsaini.guessthecelebapp 
W/System.err:     at 
com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
07-01 17:21:05.194 9836-9836/com.example.nishantsaini.guessthecelebapp 
W/System.err:     at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

FYI :I'm using the openweather API.
Please do tell if my approach was wrong or a workaround for it. Thanks. 

A:

Weather is inside the list array.
You have to iterate over the list array to get the weather object for each item.
try {
            JSONObject object = new JSONObject(result);
            JSONArray arr = object.getJSONArray("list");

            for (int i = 0; i <arr.length() ; i++) {
                JSONObject jsonpart = arr.getJSONObject(i);
                JSONArray mes = jsonpart.getJSONArray("weather");
                for (int j = 0; j <mes.length() ; j++) {
                    JSONObject weatherpart = mes.getJSONObject(j);
                    Log.i("Main",weatherpart.getString("main"));
                    Log.i("Description",weatherpart.getString("description"));
                }

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

