我想从[this link] [1]获取json:https://api.myjson.com/bins/38ln5使用改造
样本json是
{ "students": [ { "id": "1", "name": "Larzobispa" }, { "id": "2", "name": "La Cibeles" } ] }
请详细说明如何做到这一点.非常感谢,伙计们!
Retrofit将自动解析JSON Object以及JSON Array.
@GET("/register?email=example@123.com") public void responseString(Callbackresponse);
你的模型类看起来像:
public class Student{ private ArrayListstudentList = new ArrayList<>(); //getter and setters } public class StudentInfo{ private String id; private String name; //getters and setters }
然后作出回应:
@Override public void onResponse(Responseresponse, Retrofit retrofit) { if (response.isSuccess()) { Student student = response.body; Log.e("Student name", student.getStudent().get(0).getName()); // do whatever you want }else{ // get response.errorBody() } }