重命名将json转换为普通对象的arraylist值?

时间:2015-11-30 11:37:30

标签: java json arraylist

public class Student {

  String name = "jai";
  int rollno = 111;
  String address = "chennai";

  public static void main(String[] agrs) {
    Student st = new Student();
    //System.out.println(st.name);
    //System.out.println(st.rollno);
    //System.out.println(st.address);
    ArrayList al = new ArrayList();

    al.add(st);

    Gson gson = new Gson();

    String str = gson.toJson(al);

    System.out.println(str);

    ArrayList a2 = new ArrayList();

    a2.add(str);

    a2.add("us");

    System.out.println(a2);

    ArrayList a3 = gson.fromJson(str, ArrayList.class);

    System.out.println(a3);

    ArrayList a4 = gson.fromJson(str, ArrayList.class);

    a4.set(0, "ram");
     System.out.println(a4);

  }
}
  

错误:com.google.gson.JsonSyntaxException:   java.lang.IllegalStateException:预期BEGIN_ARRAY但是   BEGIN_ARRAY在第1行第2列

0 个答案:

没有答案