我因此而生气。我正在使用 Parse.com 来处理我的后端,并且我必须调用一个 Cloud Code 函数来给出这个“结构”:
{ "idShop":"asdf", "idCostumer":"zxcv", "selection": [
{"idOffer":"product1", "quantity":3 },
{"idOffer":"product2", "quantity":1 }
] }
如果我使用 curl 效果很好,但是我不知道如何使用 Android 来实现。因此,想法是将数组放入 JSON 值中。
我试图将所有信息放入一个 String 和一个 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);