【发布时间】:2016-03-01 13:56:55
【问题描述】:
我要做的是将地图添加到ArrayList,然后添加到JsonArray。我打算做的是直接将地图添加到 json 数组中。
//Initialize the ArrayList,Map and Json array
private ArrayList<Map<String, String>> itemData = new ArrayList<>();
private Map<String, String> itemselected = new HashMap<>();
JSONArray itemSelectedJson = new JSONArray();
private void selectedItems() {
if(invEstSwitch.isChecked())
{
billType = textViewEstimate.getText().toString();
}else{
billType = 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
itemData.add(index, itemselected);
itemSelectedJson= new JSONArray(Arrays.asList(itemData));
index++;
}
【问题讨论】:
-
你想在这里做什么?你为什么要这样做?
-
你遇到了什么问题
-
@AndroidNewBee 我希望它是一个 jsonArray 以便我可以解析它并使用 volley 将此数据插入 mysql 数据库。请帮助我是编程新手:) 谢谢
-
你要做什么json??你能举个例子吗
-
@Clairvoyant 我想将地图直接插入到 jsonarray 中。但是由于我不知道该怎么做,所以我首先将地图数据放入 arraylist,然后将其转换为 json 数组。有没有一种方法可以让我使用 json 数组做同样的事情。谢谢