java - Android 中的 Parse.com 云代码和 HashMap : How to set an array inside Hashmap?

标签 java android arrays json parse-platform

我因为这个而生气。我正在使用 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/

相关文章:

java - java的list add方法按值传递问题

java - 手动添加注释?

android - 如何从 Android 中的经纬度列表创建 Mapbox 热点和热图?

android - Kotlin Android - 从 fragment 复制到剪贴板

javascript - 将 map 连接到 json 文件 for 循环

php - 如何在 PHP 中调用随机函数

javascript - 如何从setState中的数组中选择特定对象?

java - 如何将SUN jvm迁移到IBM jvm

java - 如何让安卓模拟器启动更快

android - 无法构建 apk : The number of method references cannot exceed 64K