개량 신제품입니다. param을 보내고 Json을 벨로우즈 URL에서 가져 오는 방법은 무엇입니까?안드로이드의 개조?
http://xxx:8087/courier.svc/login?username=jim&password=123456
튜토리얼 용 링크가 필요합니다.
이 코드는 내 MainActivity
에 있습니다
private void loadJSON(String username, String password) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://192.168.8.11:8087/sample.svc/")
.addConverterFactory(GsonConverterFactory.create())
.build();
RequestInterface_Login request = retrofit.create(RequestInterface_Login.class);
Call<JSONResponseLogin> call = request.getJSON(username, password);
call.enqueue(new Callback<JSONResponseLogin>() {
@Override
public void onResponse(Call<JSONResponseLogin> call, Response<JSONResponseLogin> response) {
JSONResponseLogin jsonResponse = response.body();
data = new ArrayList<>(Arrays.asList(jsonResponse.getLogin()));
}
@Override
public void onFailure(Call<JSONResponseLogin> call, Throwable t) {
Log.d("Error", t.getMessage());
}
});
}
내 ModelLogin
:
public class ModelLogin {
private String username;
private String password;
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
}
내 RequestInterface_Login
:
public interface RequestInterface_Login {
@GET("/login/{username}/{password}")
Call<JSONResponseLogin> getJSON(@Path("username") String username, @Path("password") String password);
}
내 JSONResponseLogin
:
public class JSONResponseLogin {
private ModelLogin[] login;
public ModelLogin[] getLogin() {
return login;
}
}
하지만 나를 받아 NullPointerException
! 당신이 개조를 호출 들어가기 전에
{"Key":null,"Response":1}
API가 필드 또는 JSON 응답 형태로 표시되거나 URL에 직접 입력됩니까? –
내 라이브러리는 : com.squareup.retrofit2 : retrofit : 2.1.0 ' 컴파일 ('com.squareup.retrofit2 : converter-gson : 2.0.0-beta4 ') { 제외 모듈 :'retrofit ' } –
나는 개장에 대해 말하는 것이 아닙니다. 실제 API 링크를 공유 할 수 있다면 도와 드리겠습니다. –