【发布时间】:2019-09-14 20:35:03
【问题描述】:
我正在尝试在 JSON OBJECT 中传递一个 json 数组。问题是我的数组列表只包含 id,我必须循环并传递给 jsonarray,但我的 jsonarray 只获取 arraylist 的最后一个索引的值并复制到 arraylist 大小的时间。
JSONObject jsonObject = new JSONObject();
JSONArray category_ids_array = new JSONArray();
JSONObject category_items = new JSONObject();
jsonObject.put("category_ids", category_ids_array);
for (int g=0 ;g < selectedCategories.size();g++)
{
category_ids_array.put(category_items);
category_items.put("id",selectedCategories.get(g).getId());
Log.d("catids",String.valueOf(selectedCategories.get(g).getId() ) );
}
selectedCategories 数组列表包含: 1937,1994,13365;
jsononject: {"category_ids":[{"id":13365},{"id":13365},{"id":13365}]}
【问题讨论】:
-
请添加你的json
-
更新了我的答案
-
请格式化您的问题
-
先生,我需要格式化什么?