1、首先创建测试代码实体类,用于解析json数据之后存放数据的实体类,年级Grade类private String course;//课程字段private String score;//分数字段

3、创建TestGson测试类,添加一个main方法,作为测试入口

5、//解析单条有嵌套的Json数据String jsonStr1 = "{'name':'Tom', 'age':30, 'sex':'male', 'grade':{'course':'java','score':'100'}}";Gson gson1 = new Gson();Student student1 = gson1.fromJson(jsonStr1, Student.class);System.out.println(student1);
