I have been learning parsing json data in Android. I was able to parse the json data in the example which I was following. In order to test my self I started to parse some new json data. I came across this json data below:

```
    {"errors":[{"message":"Bad Authentication data","code":215}]}

```

And I am not able to parse it :(

Below is my code to parse json:

```
    public JSONObject getJSONFromURL(String url){
    JSONObject receivedJSON = null;

    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet(url);
    try {
        HttpResponse response = client.execute(request);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if(statusCode != 200){
            return null;
        }
        //Getting stream of data returned from the server using InputStream
        InputStream streamReceived = response.getEntity().getContent();
        //Reading stream of data using BufferedReader
        BufferedReader reader = new BufferedReader(new InputStreamReader(streamReceived));
        StringBuilder builder = new StringBuilder();
        String line = null;
        //Reading each line of the received data
        while((line = reader.readLine()) != null){
            builder.append(line);
        }
        streamReceived.close();
        //Converting the data read into String using StringBuilder
        String jsonData = builder.toString();
        //Converting String into JSONObject
        receivedJSONData = new JSONObject(jsonData);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //returning the JSONObject
    return receivedJSON;
}

```

And in my MainActivity I am getting the JSONObject and accordingly getting information from it. Here is how I am doing it:

```
    JSONObject jsonObj = jsonParser.getJSONFromURL(twitterURL);
    JSONArray erros = jsonObj.getJSONArray("errors");
    JSONObject error = erros.getJSONObject(0);
    String msg = error.getString("message");
    Log.d("Twitter Data", msg);

```

I am confused if to consider "errors" in the above json string as an object or an array.

Below is my logcat error:

```
02-21 10:21:08.391: E/AndroidRuntime(972): FATAL EXCEPTION: AsyncTask #1
    02-21 10:21:08.391: E/AndroidRuntime(972): java.lang.RuntimeException: An                error      occured while executing doInBackground()
    02-21 10:21:08.391: E/AndroidRuntime(972):  at android.os.AsyncTask$3.done(AsyncTask.java:299)
    02-21 10:21:08.391: E/AndroidRuntime(972):  at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
    02-21 10:21:08.391: E/AndroidRuntime(972):  at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
    02-21 10:21:08.391: E/AndroidRuntime(972):  at java.util.concurrent.FutureTask.run(FutureTask.java:239)
    02-21 10:21:08.391: E/AndroidRuntime(972):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
    02-21 10:21:08.391: E/AndroidRuntime(972):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
    02-21 10:21:08.391: E/AndroidRuntime(972):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
    02-21 10:21:08.391: E/AndroidRuntime(972):  at java.lang.Thread.run(Thread.java:856)
    02-21 10:21:08.391: E/AndroidRuntime(972): Caused by: java.lang.NullPointerException
    02-21 10:21:08.391: E/AndroidRuntime(972):  at com.example.youtubevideolist.MainActivity$FetchYoutubeVideos.doInBackground(MainActivity.java:77)
    02-21 10:21:08.391: E/AndroidRuntime(972):  at com.example.youtubevideolist.MainActivity$FetchYoutubeVideos.doInBackground(MainActivity.java:1)
    02-21 10:21:08.391: E/AndroidRuntime(972):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
    02-21 10:21:08.391: E/AndroidRuntime(972):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
    02-21 10:21:08.391: E/AndroidRuntime(972):  ... 4 more
    02-21 10:21:09.731: E/WindowManager(972): Activity com.example.youtubevideolist.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40ce51d8 V.E..... R......D 0,0-729,324} that was originally added here
    02-21 10:21:09.731: E/WindowManager(972): android.view.WindowLeaked: Activity com.example.youtubevideolist.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40ce51d8 V.E..... R......D 0,0-729,324} that was originally added here
    02-21 10:21:09.731: E/WindowManager(972):   at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
    02-21 10:21:09.731: E/WindowManager(972):   at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
    02-21 10:21:09.731: E/WindowManager(972):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
    02-21 10:21:09.731: E/WindowManager(972):   at android.app.Dialog.show(Dialog.java:281)
    02-21 10:21:09.731: E/WindowManager(972):   at com.example.youtubevideolist.MainActivity$FetchYoutubeVideos.onPreExecute(MainActivity.java:56)
    02-21 10:21:09.731: E/WindowManager(972):   at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
    02-21 10:21:09.731: E/WindowManager(972):   at android.os.AsyncTask.execute(AsyncTask.java:534)
    02-21 10:21:09.731: E/WindowManager(972):   at com.example.youtubevideolist.MainActivity.onCreate(MainActivity.java:38)
    02-21 10:21:09.731: E/WindowManager(972):   at android.app.Activity.performCreate(Activity.java:5104)
    02-21 10:21:09.731: E/WindowManager(972):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    02-21 10:21:09.731: E/WindowManager(972):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
    02-21 10:21:09.731: E/WindowManager(972):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    02-21 10:21:09.731: E/WindowManager(972):   at android.app.ActivityThread.access$600(ActivityThread.java:141)
    02-21 10:21:09.731: E/WindowManager(972):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    02-21 10:21:09.731: E/WindowManager(972):   at android.os.Handler.dispatchMessage(Handler.java:99)
    02-21 10:21:09.731: E/WindowManager(972):   at android.os.Looper.loop(Looper.java:137)
    02-21 10:21:09.731: E/WindowManager(972):   at android.app.ActivityThread.main(ActivityThread.java:5041)
    02-21 10:21:09.731: E/WindowManager(972):   at java.lang.reflect.Method.invokeNative(Native Method)
    02-21 10:21:09.731: E/WindowManager(972):   at java.lang.reflect.Method.invoke(Method.java:511)
    02-21 10:21:09.731: E/WindowManager(972):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    02-21 10:21:09.731: E/WindowManager(972):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    02-21 10:21:09.731: E/WindowManager(972):   at dalvik.system.NativeStart.main(Native   Method)

```

Any help on this is very much appreciated :) Thanks in advance :)