androidjsonapiandroid-studiojson-arrayagg

how to set Text of total amount of prouduct which got from API?


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);
            }
 

Solution

  • 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}
    ]"