Retrofit build = new Retrofit.Builder()
.baseUrl(Constant.BASE_URL)
//使用gson解析时,要添加
.addConverterFactory(GsonConverterFactory.create())
.build();
MyServerInterferce myServerInterferce= build.create(MyServerInterferce.class);
Call<DataDataBean> call = myServerInterferce.getLatestJsonString();
call.enqueue(new Callback<DataDataBean>() {
@Override
public void onResponse(Call<DataDataBean> call, Response<DataDataBean> response) {
if (response.isSuccess()&&response.body()!=null){
Log.i("---", response.body().getCount()+"");
text.setText(response.body().getItems().toString());
}
}
@Override
public void onFailure(Call<DataDataBean> call, Throwable t) {
}
});
public interface MyServerInterferce {
@GET("article/list/latest?page=1")
Call<DataDataBean> getLatestJsonString();
@GET("article/list/{type}?")
Call<DataDataBean> getLatestJsonString(@Path("type")String type,@Query("page")int page);
}
public class Constant {
public final static String BASE_URL="http://m2.qiushibaike.com/";
}