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());
}
?>
getParams()method code in the question..