Java 利用Gson将json字符串转换为List>

json字符串类似于:

[ { "userPhone": "123", "userNo": "123-2", "userPassword": "123", "userName": "123" }, { "userPhone": "123", "userNo": "123-3", "userPassword": "123", "userName": "123" }, { "userPhone": "123", "userNo": "123-5", "userPassword": "\u67f1\u5b50", "userName": "1265544" }]

Java处理:

1 Gson gson = new Gson();
2 List> resultList = gson.fromJson(responseStr, new TypeToken>>(){}.getType());

Gson导入:

  Android:dependencies中添加

compile 'com.google.code.gson:gson:2.7'

  Java:Mevan项目,pom中添加

1 
2 <dependency>
3     <groupId>com.google.code.gsongroupId>
4     <artifactId>gsonartifactId>
5     <version>2.3.1version>
6 dependency>

  非Mevan项目,自行去Mevan仓库中寻找jar导入项目:http://mvnrepository.com/

转载于:https://www.cnblogs.com/fx-blog/p/8310350.html

你可能感兴趣的:(json,java,移动开发)