如何将arraylist转换为hashmap?

时间:2015-12-14 10:40:26

标签: json hashmap

    Gson gson = new Gson();
    HashMap<String, BeanClass> hm = new HashMap<>();
    hm.put("First", beanclass1);
    hm.put("Second", beanclass2);
    hm.put("Third", beanclass3);
    hm.put("Fourth", beanclass4);
    hm.put("Fifth", beanclass5);

    ArrayList al = new ArrayList();
    al.add(hm);

    String st = gson.toJson(al);
    System.out.println(st);

    ArrayList al2 = gson.fromJson(st, ArrayList.class);

    System.out.println(al2);

    //  HashMap hm1= (HashMap) al2.get(0);

     // System.out.println(hm1);


    how to convert arraylist to hashmap?here hm is hashmap  . .then 
      converted to arraylist..(al)..then al is convertd to al2  
    arrayobject ..finally how to al2 arrayobject to hashmap object?

rror:com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:预期为BEGIN_ARRAY但在第1行第2列为BEGIN_ARRAY

0 个答案:

没有答案