Question: I am working on android application and I need to parse my json object with data. How you can see I create JSONParser class and try to use asynctask but there is something wrong and I can't understand where is the problem. Every time I use it resultJSON is null. Hope that you can give me an advice!

```
public class JSONParser {
    private String resultJSON;

public JSONArray getJSON(String url) throws JSONException {
    Parser parser = new Parser();
    parser.execute(url);
    return json;
}

private class Parser extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {
        for (String url : urls) {
            StringBuilder builder = new StringBuilder();
            HttpClient client = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(url);
            try {
                HttpResponse response = client.execute(httpGet);
                StatusLine statusLine = response.getStatusLine();
                int statusCode = statusLine.getStatusCode();
                if (statusCode == 200) {
                    HttpEntity entity = response.getEntity();
                    InputStream content = entity.getContent();
                    BufferedReader reader = new BufferedReader(
                            new InputStreamReader(content));
                    String line;
                    while ((line = reader.readLine()) != null) {
                        builder.append(line);
                    }
                    resultJSON = builder.toString();
                } else {
                    Log.e(JSONParser.class.toString(), "Failed to download file");
                }
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
      }
      return resultJSON;
    }
    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        try {
            json = new JSONArray(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
}

```

Answer: 
Why don't you `JSONArray json = new JSONArray(resultJSON);` do this on post execute method of async task . 

And i will not suggest varevarao way , as it will create extra burden of one thread .
You should use the [get() method](http://developer.android.com/reference/android/os/AsyncTask.html#get%28%29) of the AsyncTask class to retrieve the result of the task. It waits for the task to complete and gets the result (which means it'd be best if you enclose it within a separate thread with a progress dialog or just a background thread).

```
public JSONArray getJSON(String url) throws JSONException {
    Parser parser = new Parser();
    parser.execute(url);
    resultJSON = parser.get(); // Probably put this in a Thread to avoid spending too much time waiting for a result on the main thread
    JSONArray json = new JSONArray(resultJSON);
    return json;
}

```