我因为这个而生气。我正在使用 Parse.com 来处理我的后端,并且我必须调用给出此“结构”的云代码函数:
{ "idShop":"asdf", "idCostumer":"zxcv", "selection": [
{"idOffer":"product1", "quantity":3 },
{"idOffer":"product2", "quantity":1 }
] }
如果我使用curl,它工作得很好,但是,我不知道如何在Android 上做到这一点。因此,我们的想法是将数组放入 JSON 值中。
我尝试将所有信息放入字符串和 HashMap 数组中,但没有结果。
有什么想法吗?
感谢您的帮助! :)
<小时/>苏尼尔回答后:
这就是我正在做的事情,但不起作用:
HashMap<String, String [] > params = new HashMap<String, String []>();
params.put("idCostumer", new String[]{costumerId});
params.put("idShop", new String[]{idShop});
OfferListItem item;
ArrayList<String> selectionList = new ArrayList<String>();
for(int i=0; i<offerList.size();i++){
item = offerList.get(i);
if (item.getClicks()>0){
selectionList.add("\"idOffer\":"+item.getId()+", "+"\"quantity\":"+item.getClicks());
}
}
String [] selection = new String [selectionList.size()];
for (int i=0;i<selection.length;i++) {
selection[i]=selectionList.get(i);
}
params.put("selection", selection);
最佳答案
根据Parse's Android Guide ,用于数组的正确数据类型是 JSONArray
。尝试使用 JSONArray
代替 String []
。
关于java - Android 中的 Parse.com 云代码和 HashMap : How to set an array inside Hashmap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18399058/