import java.util.List;
import com.alibaba.fastjson.JSON;
import com.yz.javabean.Student;
import com.yz.utils.HttpUtils;
public class Demo11FastJson {
public static void main(String[] args) {
String baseUrl1 = "http://10.0.158.239:8080/Day22_Server/JsonServlet?action=student";
String baseUrl2 = "http://10.0.158.239:8080/Day22_Server/JsonServlet?action=students";
String json1 = HttpUtils.getJsonFromNetWork(baseUrl1);// {}
String json2 = HttpUtils.getJsonFromNetWork(baseUrl2);// []
//阿里巴巴FAST解析:解析对象
Student stu = JSON.parseObject(json1, Student.class);
System.out.println(stu);
//阿里巴巴Fast-json:解析一个集合
List<Student> list = JSON.parseArray(json2, Student.class);
}
}
import com.alibaba.fastjson.JSON;
import com.yz.javabean.Student;
import com.yz.utils.HttpUtils;
public class Demo11FastJson {
public static void main(String[] args) {
String baseUrl1 = "http://10.0.158.239:8080/Day22_Server/JsonServlet?action=student";
String baseUrl2 = "http://10.0.158.239:8080/Day22_Server/JsonServlet?action=students";
String json1 = HttpUtils.getJsonFromNetWork(baseUrl1);// {}
String json2 = HttpUtils.getJsonFromNetWork(baseUrl2);// []
//阿里巴巴FAST解析:解析对象
Student stu = JSON.parseObject(json1, Student.class);
System.out.println(stu);
//阿里巴巴Fast-json:解析一个集合
List<Student> list = JSON.parseArray(json2, Student.class);
}
}