0

I want to display total amount of product which I got from API. Here is the code which i implemented. Error shows that onErrorResponse: org.json.JSONException: Value Final:92 of type java.lang.String cannot be converted to JSONArray

private void getTotal(Integer intquantity) {
    strproquantity = qty.getText().toString();
    String url = Config.URL + "apiurl.aspx?msg=CalculateFnMRPWithQty%20" + strprocode + "%20" + intquantity;;
   // loading.show();
    Log.d("TAG" + "quantity url", url);
    //String Strprototal = strprototal;
    JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
        @RequiresApi(api = Build.VERSION_CODES.O)
        @Override
        public void onResponse(JSONArray response) {
            Log.d("TAG", "JSONObject-----------" + response.toString());
           parseData(response);
        }
    }

the code of parse data is

   private void parseData(JSONArray response) {
    for (int i = 0; i < response.length(); i++) {
        Log.d("TAG", "response: " + response);
        loading.dismiss();
        try {
            JSONObject jsonObject = response.getJSONObject(i);
           strproquantity = jsonObject.getString("Quantity");
           totalprize.setText("" + strprototal);
            }
 
Shweta
  • 23
  • 5
  • What is the issue exactly? Where _strprototal_ stands for? – Piyush Nov 22 '21 at 06:46
  • @Piyush strprototal is a string which i used to store the value of total amount and my issue is i total amount of product is not showing. – Shweta Nov 22 '21 at 06:52

1 Answers1

0

Since I can't comment yet I'll write here. Show us your response body. It may contain extra quotes like this or have other issues:

"[
  {some objects}
]"
MikhailM
  • 71
  • 5
  • "Final:92" it is response body – Shweta Nov 22 '21 at 08:52
  • @Shweta, it's not a valid JSON or JSON array format. Learn how to properly format JSON. Here is a [JSON validator](https://jsonformatter.curiousconcept.com) you can use to check yourself. – MikhailM Nov 22 '21 at 10:18
  • i know but this kind of response which i get from api – Shweta Nov 22 '21 at 10:25
  • Well, then you need another type of request object since JSONRequest and JSONArrayRequest work only with JSON response. – MikhailM Nov 22 '21 at 10:44