org.json.JSONException in volley












0















I am parsing json using volley but its not working and getting error. Follwing is my code and json reponse. please help me to solve this



 private void getStaffList() {

showpDialog();
RequestQueue requestQueue = Volley.newRequestQueue(this);
final String url = "url";


try {

final JSONObject jsonObj = new JSONObject();


jsonObj.put("username", "test");
jsonObj.put("password", "123456");


JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
url, jsonObj, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("TAG", "Main response=" + response);


staffarraylist=new ArrayList<DataModel>();;
try {
JSONObject jobSuccess=response.getJSONObject("TABLE_DATA");
Log.d("TAG", "JSONObj response=" + jobSuccess);
JSONArray jarMyData=jobSuccess.getJSONArray("data");
Log.d("TAG", "JSONArray response=" + jarMyData);
for (int i = 0; i < jarMyData.length(); i++) {
JSONArray jar = jarMyData.getJSONArray(i);

DataModel movie = new DataModel();
movie.setName(jar.getString(0));
movie.setOccupation(jar.getString(1));
movie.setPlace(jar.getString(2));
movie.setId(jar.getString(3));
movie.setDate(jar.getString(4));
movie.setPrice(jar.getString(5));
staffarraylist.add(movie);
}
}catch (JSONException e)
{
Log.d("JSONException",e.toString());
}


rcAdapter = new RecyclerViewAdapterHome(MainActivity.this, staffarraylist);
recyclerView.setAdapter(rcAdapter);

hidepDialog();

}

}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("TAG", "JSONObj Error: " + error.getMessage());
hidepDialog();
//Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
// hide the progress dialog
}
});

requestQueue.add(jsonObjReq);

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

}


Logcat



Main response={"TABLE_DATA":"{"data":[["Tiger Nixon","System Architect","Edinburgh","5421","2011/04/25","$320,800"],["Garrett Winters","Accountant",....so on



D/JSONException: org.json.JSONException: Value {"data":[["Tiger Nixon","System Architect","Edinburgh","5421","2011/04/25","$320,800"],["Garrett Winters","Accountant","Tokyo","8422","2011/07/25","$










share|improve this question





























    0















    I am parsing json using volley but its not working and getting error. Follwing is my code and json reponse. please help me to solve this



     private void getStaffList() {

    showpDialog();
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    final String url = "url";


    try {

    final JSONObject jsonObj = new JSONObject();


    jsonObj.put("username", "test");
    jsonObj.put("password", "123456");


    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
    url, jsonObj, new Response.Listener<JSONObject>() {
    @Override
    public void onResponse(JSONObject response) {
    Log.d("TAG", "Main response=" + response);


    staffarraylist=new ArrayList<DataModel>();;
    try {
    JSONObject jobSuccess=response.getJSONObject("TABLE_DATA");
    Log.d("TAG", "JSONObj response=" + jobSuccess);
    JSONArray jarMyData=jobSuccess.getJSONArray("data");
    Log.d("TAG", "JSONArray response=" + jarMyData);
    for (int i = 0; i < jarMyData.length(); i++) {
    JSONArray jar = jarMyData.getJSONArray(i);

    DataModel movie = new DataModel();
    movie.setName(jar.getString(0));
    movie.setOccupation(jar.getString(1));
    movie.setPlace(jar.getString(2));
    movie.setId(jar.getString(3));
    movie.setDate(jar.getString(4));
    movie.setPrice(jar.getString(5));
    staffarraylist.add(movie);
    }
    }catch (JSONException e)
    {
    Log.d("JSONException",e.toString());
    }


    rcAdapter = new RecyclerViewAdapterHome(MainActivity.this, staffarraylist);
    recyclerView.setAdapter(rcAdapter);

    hidepDialog();

    }

    }, new Response.ErrorListener() {

    @Override
    public void onErrorResponse(VolleyError error) {
    VolleyLog.d("TAG", "JSONObj Error: " + error.getMessage());
    hidepDialog();
    //Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
    // hide the progress dialog
    }
    });

    requestQueue.add(jsonObjReq);

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

    }


    Logcat



    Main response={"TABLE_DATA":"{"data":[["Tiger Nixon","System Architect","Edinburgh","5421","2011/04/25","$320,800"],["Garrett Winters","Accountant",....so on



    D/JSONException: org.json.JSONException: Value {"data":[["Tiger Nixon","System Architect","Edinburgh","5421","2011/04/25","$320,800"],["Garrett Winters","Accountant","Tokyo","8422","2011/07/25","$










    share|improve this question



























      0












      0








      0








      I am parsing json using volley but its not working and getting error. Follwing is my code and json reponse. please help me to solve this



       private void getStaffList() {

      showpDialog();
      RequestQueue requestQueue = Volley.newRequestQueue(this);
      final String url = "url";


      try {

      final JSONObject jsonObj = new JSONObject();


      jsonObj.put("username", "test");
      jsonObj.put("password", "123456");


      JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
      url, jsonObj, new Response.Listener<JSONObject>() {
      @Override
      public void onResponse(JSONObject response) {
      Log.d("TAG", "Main response=" + response);


      staffarraylist=new ArrayList<DataModel>();;
      try {
      JSONObject jobSuccess=response.getJSONObject("TABLE_DATA");
      Log.d("TAG", "JSONObj response=" + jobSuccess);
      JSONArray jarMyData=jobSuccess.getJSONArray("data");
      Log.d("TAG", "JSONArray response=" + jarMyData);
      for (int i = 0; i < jarMyData.length(); i++) {
      JSONArray jar = jarMyData.getJSONArray(i);

      DataModel movie = new DataModel();
      movie.setName(jar.getString(0));
      movie.setOccupation(jar.getString(1));
      movie.setPlace(jar.getString(2));
      movie.setId(jar.getString(3));
      movie.setDate(jar.getString(4));
      movie.setPrice(jar.getString(5));
      staffarraylist.add(movie);
      }
      }catch (JSONException e)
      {
      Log.d("JSONException",e.toString());
      }


      rcAdapter = new RecyclerViewAdapterHome(MainActivity.this, staffarraylist);
      recyclerView.setAdapter(rcAdapter);

      hidepDialog();

      }

      }, new Response.ErrorListener() {

      @Override
      public void onErrorResponse(VolleyError error) {
      VolleyLog.d("TAG", "JSONObj Error: " + error.getMessage());
      hidepDialog();
      //Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
      // hide the progress dialog
      }
      });

      requestQueue.add(jsonObjReq);

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

      }


      Logcat



      Main response={"TABLE_DATA":"{"data":[["Tiger Nixon","System Architect","Edinburgh","5421","2011/04/25","$320,800"],["Garrett Winters","Accountant",....so on



      D/JSONException: org.json.JSONException: Value {"data":[["Tiger Nixon","System Architect","Edinburgh","5421","2011/04/25","$320,800"],["Garrett Winters","Accountant","Tokyo","8422","2011/07/25","$










      share|improve this question
















      I am parsing json using volley but its not working and getting error. Follwing is my code and json reponse. please help me to solve this



       private void getStaffList() {

      showpDialog();
      RequestQueue requestQueue = Volley.newRequestQueue(this);
      final String url = "url";


      try {

      final JSONObject jsonObj = new JSONObject();


      jsonObj.put("username", "test");
      jsonObj.put("password", "123456");


      JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
      url, jsonObj, new Response.Listener<JSONObject>() {
      @Override
      public void onResponse(JSONObject response) {
      Log.d("TAG", "Main response=" + response);


      staffarraylist=new ArrayList<DataModel>();;
      try {
      JSONObject jobSuccess=response.getJSONObject("TABLE_DATA");
      Log.d("TAG", "JSONObj response=" + jobSuccess);
      JSONArray jarMyData=jobSuccess.getJSONArray("data");
      Log.d("TAG", "JSONArray response=" + jarMyData);
      for (int i = 0; i < jarMyData.length(); i++) {
      JSONArray jar = jarMyData.getJSONArray(i);

      DataModel movie = new DataModel();
      movie.setName(jar.getString(0));
      movie.setOccupation(jar.getString(1));
      movie.setPlace(jar.getString(2));
      movie.setId(jar.getString(3));
      movie.setDate(jar.getString(4));
      movie.setPrice(jar.getString(5));
      staffarraylist.add(movie);
      }
      }catch (JSONException e)
      {
      Log.d("JSONException",e.toString());
      }


      rcAdapter = new RecyclerViewAdapterHome(MainActivity.this, staffarraylist);
      recyclerView.setAdapter(rcAdapter);

      hidepDialog();

      }

      }, new Response.ErrorListener() {

      @Override
      public void onErrorResponse(VolleyError error) {
      VolleyLog.d("TAG", "JSONObj Error: " + error.getMessage());
      hidepDialog();
      //Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
      // hide the progress dialog
      }
      });

      requestQueue.add(jsonObjReq);

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

      }


      Logcat



      Main response={"TABLE_DATA":"{"data":[["Tiger Nixon","System Architect","Edinburgh","5421","2011/04/25","$320,800"],["Garrett Winters","Accountant",....so on



      D/JSONException: org.json.JSONException: Value {"data":[["Tiger Nixon","System Architect","Edinburgh","5421","2011/04/25","$320,800"],["Garrett Winters","Accountant","Tokyo","8422","2011/07/25","$







      android json android-volley jsonexception jsonobjectrequest






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 15:00







      chris

















      asked Nov 24 '18 at 13:58









      chrischris

      1321328




      1321328
























          1 Answer
          1






          active

          oldest

          votes


















          0














          First check that your json format is correct or not by clicking here and paste your json for checking. If the response is correct then use Gson. It will parse the response without any error.






          share|improve this answer
























          • response is ok, can you tell what is the use of Gson in my case? how to use.

            – chris
            Nov 24 '18 at 15:10











          • It will convert your response into a pojo class.So you can use this class instead of converting json manually.

            – Jawad Ahmed
            Nov 24 '18 at 15:12











          • can you help me with that please

            – chris
            Nov 24 '18 at 15:13











          • Yes sure. Go to <a href="pojo.sodhanalibrary.com/">here.</a>

            – Jawad Ahmed
            Nov 24 '18 at 15:15











          • Copy paste your json response .It will create a java class for you put it in your project. and then add gson library to your project.

            – Jawad Ahmed
            Nov 24 '18 at 15:16











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458894%2forg-json-jsonexception-in-volley%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          First check that your json format is correct or not by clicking here and paste your json for checking. If the response is correct then use Gson. It will parse the response without any error.






          share|improve this answer
























          • response is ok, can you tell what is the use of Gson in my case? how to use.

            – chris
            Nov 24 '18 at 15:10











          • It will convert your response into a pojo class.So you can use this class instead of converting json manually.

            – Jawad Ahmed
            Nov 24 '18 at 15:12











          • can you help me with that please

            – chris
            Nov 24 '18 at 15:13











          • Yes sure. Go to <a href="pojo.sodhanalibrary.com/">here.</a>

            – Jawad Ahmed
            Nov 24 '18 at 15:15











          • Copy paste your json response .It will create a java class for you put it in your project. and then add gson library to your project.

            – Jawad Ahmed
            Nov 24 '18 at 15:16
















          0














          First check that your json format is correct or not by clicking here and paste your json for checking. If the response is correct then use Gson. It will parse the response without any error.






          share|improve this answer
























          • response is ok, can you tell what is the use of Gson in my case? how to use.

            – chris
            Nov 24 '18 at 15:10











          • It will convert your response into a pojo class.So you can use this class instead of converting json manually.

            – Jawad Ahmed
            Nov 24 '18 at 15:12











          • can you help me with that please

            – chris
            Nov 24 '18 at 15:13











          • Yes sure. Go to <a href="pojo.sodhanalibrary.com/">here.</a>

            – Jawad Ahmed
            Nov 24 '18 at 15:15











          • Copy paste your json response .It will create a java class for you put it in your project. and then add gson library to your project.

            – Jawad Ahmed
            Nov 24 '18 at 15:16














          0












          0








          0







          First check that your json format is correct or not by clicking here and paste your json for checking. If the response is correct then use Gson. It will parse the response without any error.






          share|improve this answer













          First check that your json format is correct or not by clicking here and paste your json for checking. If the response is correct then use Gson. It will parse the response without any error.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '18 at 15:05









          Jawad AhmedJawad Ahmed

          796




          796













          • response is ok, can you tell what is the use of Gson in my case? how to use.

            – chris
            Nov 24 '18 at 15:10











          • It will convert your response into a pojo class.So you can use this class instead of converting json manually.

            – Jawad Ahmed
            Nov 24 '18 at 15:12











          • can you help me with that please

            – chris
            Nov 24 '18 at 15:13











          • Yes sure. Go to <a href="pojo.sodhanalibrary.com/">here.</a>

            – Jawad Ahmed
            Nov 24 '18 at 15:15











          • Copy paste your json response .It will create a java class for you put it in your project. and then add gson library to your project.

            – Jawad Ahmed
            Nov 24 '18 at 15:16



















          • response is ok, can you tell what is the use of Gson in my case? how to use.

            – chris
            Nov 24 '18 at 15:10











          • It will convert your response into a pojo class.So you can use this class instead of converting json manually.

            – Jawad Ahmed
            Nov 24 '18 at 15:12











          • can you help me with that please

            – chris
            Nov 24 '18 at 15:13











          • Yes sure. Go to <a href="pojo.sodhanalibrary.com/">here.</a>

            – Jawad Ahmed
            Nov 24 '18 at 15:15











          • Copy paste your json response .It will create a java class for you put it in your project. and then add gson library to your project.

            – Jawad Ahmed
            Nov 24 '18 at 15:16

















          response is ok, can you tell what is the use of Gson in my case? how to use.

          – chris
          Nov 24 '18 at 15:10





          response is ok, can you tell what is the use of Gson in my case? how to use.

          – chris
          Nov 24 '18 at 15:10













          It will convert your response into a pojo class.So you can use this class instead of converting json manually.

          – Jawad Ahmed
          Nov 24 '18 at 15:12





          It will convert your response into a pojo class.So you can use this class instead of converting json manually.

          – Jawad Ahmed
          Nov 24 '18 at 15:12













          can you help me with that please

          – chris
          Nov 24 '18 at 15:13





          can you help me with that please

          – chris
          Nov 24 '18 at 15:13













          Yes sure. Go to <a href="pojo.sodhanalibrary.com/">here.</a>

          – Jawad Ahmed
          Nov 24 '18 at 15:15





          Yes sure. Go to <a href="pojo.sodhanalibrary.com/">here.</a>

          – Jawad Ahmed
          Nov 24 '18 at 15:15













          Copy paste your json response .It will create a java class for you put it in your project. and then add gson library to your project.

          – Jawad Ahmed
          Nov 24 '18 at 15:16





          Copy paste your json response .It will create a java class for you put it in your project. and then add gson library to your project.

          – Jawad Ahmed
          Nov 24 '18 at 15:16


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458894%2forg-json-jsonexception-in-volley%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Lallio

          Futebolista

          Jornalista