Java利用gson,将字符串转化为list

  public static void main(String[] args) {
    String jsonString = "[1,2,3,4]";

    Gson gson = new Gson();
    Type type = new TypeToken<List<Integer>>() {
    }.getType();
    List<Integer> list = gson.fromJson(jsonString, type);
    System.out.println(list);

  }
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
    </dependency>

 

posted @ 2020-07-10 19:01  i孤独行者  阅读(5554)  评论(0编辑  收藏  举报