解决方案 »

  1.   

    明显是两个对象,你转为一个是啥意思啊,先遍历出来array的每个子集,然后再转。
      

  2.   


    List<Catalog> listCatalogs = new Gson().fromJson(jsonStr , new TypeToken<List<Catalog>>() {}.getType());我用上面的方式取的时候,也报错了啊
      

  3.   

    Catalog catalog = gson.fromJson(
    "{\"code\": \"2\",\"content\": \"2222\",\"createTime\": null}",
    Catalog.class);
    System.out.println(catalog.getCode());你这样看看会不会错,你先定位哪里开始错的。
      

  4.   

    List<Catalog> listCatalogs = new Gson()
    .fromJson(
    "[{\"code\": \"2\",\"content\": \"2222\",\"createTime\": null},{\"code\": \"1\",\"content\": \"sfsdf\",\"createTime\": 123132}]",
    new TypeToken<List<Catalog>>() {
    }.getType());
    System.out.println(listCatalogs.get(0).getCode());
    System.out.println(listCatalogs.get(1).getCode());那你在这样试试,如果没问题,那就是没有正确读到json字符串了,你打印下看是否读取到了
      

  5.   


    试了,没问题。
    我输出了jsonStr:[
      {
        "code": "2",
        "content": "2222",
        "createTime": null
      },
      {
        "code": "1",
        "content": "sfsdf",
        "createTime": null
      }
    ]
      

  6.   

    根据抛出的异常,应该是fromJson(jsonStr, Catalog.class)这个方法有问题。