Java 如何将Hashmap转换为ArrayList private void showResult(){ 试一试{ JSONObject JSONObject=新的JSONObject(mJsonString); JSONArray JSONArray=jsonObject.getJSONArray(TAG_JSON); 对于(int i=0;i
在下面添加行)Java 如何将Hashmap转换为ArrayList private void showResult(){ 试一试{ JSONObject JSONObject=新的JSONObject(mJsonString); JSONArray JSONArray=jsonObject.getJSONArray(TAG_JSON); 对于(int i=0;i,java,json,firebase,Java,Json,Firebase,在下面添加行) private void showResult(){ try { JSONObject jsonObject = new JSONObject(mJsonString); JSONArray jsonArray = jsonObject.getJSONArray(TAG_JSON); for(int i=0;i<jsonArray.length();i++){
private void showResult(){
try {
JSONObject jsonObject = new JSONObject(mJsonString);
JSONArray jsonArray = jsonObject.getJSONArray(TAG_JSON);
for(int i=0;i<jsonArray.length();i++){
JSONObject item = jsonArray.getJSONObject(i);
String id = item.getString(TAG_ID);
HashMap<String,String> hashMap = new HashMap<>();
hashMap.put(TAG_ID, id);
String aa = hashMap.get("user_no");
mArrayList.add(hashMap);
}
}
}
List List=new ArrayList();
HashMap HashMap=新的HashMap();
hashMap.put(TAG_ID,ID);
list.add(hashMap)
您尝试过的其他方法是什么?创建一个包含两个变量的复合对象:key和content。迭代映射,为每个元素创建其key和value的实例,并将它们存储在列表中您的代码似乎创建了一个ArrayList
。这不是您想要的吗?我想将hashmap中的数据映射到ArrayList或其他Things关联…您只丢失了一半信息示例{index 0:TAG_ID=1,index 1:TAG_ID=2,index 2:TAG_ID=3}然后将Hashmap添加到ArrayList[0]=1,list[1]=2,list[2]=3I编辑了我的答案
List<HashMap> list = new ArrayList<HashMap>();
HashMap<String,String> hashMap = new HashMap<>();
hashMap.put(TAG_ID, id);
list.add(hashMap)