1

I have used getParams() method but I dont know how to use the JsonArrayRequest method. I think this is how it should look like.

 JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.POST, INVEST_URL,
            itemSelectedJson, new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(jsonArrayRequest);

The below mentioned code creates an JsonArray.

 private void selectedItems() {

    billType = (invEstSwitch.isChecked() ? textViewEstimate : textViewInvoice)
            .getText().toString();

    itemselected.put("custInfo", custSelected.toString());
    itemselected.put("invoiceNo", textViewInvNo.getText().toString());
    itemselected.put("barcode", barCode.getText().toString());
    itemselected.put("desc", itemDesc.getText().toString());
    itemselected.put("weight", weightLine.getText().toString());
    itemselected.put("rate", rateAmount.getText().toString());
    itemselected.put("makingAmt", makingAmount.getText().toString());
    itemselected.put("net_rate", netRate.getText().toString());
    itemselected.put("itemTotal", itemtotal.getText().toString());
    itemselected.put("vat", textViewVat.getText().toString());
    itemselected.put("sum_total", textViewSum.getText().toString());
    itemselected.put("bill_type", billType);
    itemselected.put("date", textViewCurrentDate.getText().toString());

    //Add the map to the Array
    itemSelectedJson.put(itemselected);
    index++;
}

This is the json array that is generated.

["{custInfo=Ujwal 9975022560, rate=24000, weight=21.00000, desc=GENTS ANGTHI 22k NO STONE, makingAmt=200, vat=RS.3064.38, itemTotal=51073, sum_total=RS.156283.38, barcode=BQSP78BB, net_rate=24200, date=2015-11-30, invoiceNo=1, bill_type=Invoice}","{custInfo=Ujwal 9975022560, rate=24000, weight=21.00000, desc=GENTS ANGTHI 22k NO STONE, makingAmt=200, vat=RS.3064.38, itemTotal=51073, sum_total=RS.156283.38, barcode=BQSP78BB, net_rate=24200, date=2015-11-30, invoiceNo=1, bill_type=Invoice}","{custInfo=Ujwal 9975022560, rate=24000, weight=21.00000, desc=GENTS ANGTHI 22k NO STONE, makingAmt=200, vat=RS.3064.38, itemTotal=51073, sum_total=RS.156283.38, barcode=BQSP78BB, net_rate=24200, date=2015-11-30, invoiceNo=1, bill_type=Invoice}"]

Please give me some advice on how to use the volley lib and parsing this type of json array in android.

This is the getParams code that I was using to insert one item detail into the database.

 @Override
            protected Map<String, String> getParams() throws AuthFailureError {

                Map<String, String> params = new HashMap<>();
                params.put(KEY_CUSTINFO, custInfo);
                params.put(KEY_INVOICENO, invoiceNo);
                params.put(KEY_SBARCODE, barcode);
                params.put(KEY_DESC, desc);
                params.put(KEY_WEIGHT, weight);
                params.put(KEY_RATE, rate);
                params.put(KEY_MAKINGAMT, makingAmt);
                params.put(KEY_NETRATE, net_rate);
                params.put(KEY_ITEMTOTAL, itemTotal);
                params.put(KEY_VAT, vat);
                params.put(KEY_SUMTOTAL, sum_total);
                params.put(KEY_BILLTYPE, bill_type);
                params.put(KEY_DATE, date);

                return params;
            }

            @Override
            protected String getParamsEncoding() {
                return super.getParamsEncoding();
            }
        };
        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);

This is my php code

 <?php
require "init.php";
$json = file_get_contents('php://input'); 
$data = json_decode($json,true);
//echo $obj+"";
$custInfo = $data['custInfo'];
$rate = $data['rate'];
$weight= $data['weight'];
$desc= $data['desc'];
$makingAmt= $data['makingAmt'];
$vat= $data['vat'];
$itemTotal= $data['itemTotal'];
$sum_total= $data['sum_total'];
$barcode= $data['barcode'];
$net_rate= $data[net_rate''];
$date= $data['date'];
$invoiceNo= $data['invoiceNo'];
$bill_type= $data['bill_type'];
$sql = "INSERT INTO selected_items (custInfo, invoiceNo, barcode, desc, weight, rate, makingAmt,net_rate,itemTotal,vat,sum_total,bill_type,date) VALUES
('$custInfo','$invoiceNo','$barcode','$desc','$weight','$rate','$makingAmt','$net_rate','$itemTotal','$vat','$sum_total','$bill_type','$date')";
 if(!mysqli_query($sql,$con))
    {
        die('Error : ' . mysql_error());
    }
?>
12
  • 1
    Please post your getParams() method code in the question.. Commented Nov 30, 2015 at 9:31
  • @Droidwala I have added my getParams() method but I don't know how that would help. Commented Nov 30, 2015 at 9:36
  • But what is the error you are facing in your case? Commented Nov 30, 2015 at 9:36
  • @Droidwala I want to know how I can send an Jsonarray using volley? canyou help me with it? Commented Nov 30, 2015 at 9:38
  • @AndroidNewBee Do you want to know how to implement JsonArrayRequest and the equivalent php code for it? Commented Nov 30, 2015 at 9:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.