#将Json字符串解析成集合,但是通过键值获取数据时总是为null
#
public class Gsontest {
public static void main(String[] args) {
String jsonstr="{\"id\":\"1500100001\",\"name\":\"施笑槐\",\"age\":\"22\",\"gender\":\"女\",\"班级\":\"文科六班\"}";
Gson gson = new Gson();
HashMap<String, String> map = new HashMap<String, String>();
HashMap hashMap = gson.fromJson(jsonstr, map.getClass());
// System.out.println(hashMap);
System.out.println(map.get("gender"));
}
}
#结果如下:
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/225135972136140.png "=600 #left")