Retrofit
으로 json
형식을 읽으려면 어떻게해야합니까?json with Retrofit - Android를 읽으시겠습니까?
{"Key":null,"Response":1}
주의 사항
내가 사용하고 :
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.google.code.gson:gson:2.6.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
내 코드 것은 :
private void loadJSON(String username, String password) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://192.168.8.11:8087/")
.addConverterFactory(GsonConverterFactory.create(new Gson()))
.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());
}
});
}
그리고 JSONResponseLogin
:
public class JSONResponseLogin {
private ModelLogin[] login;
public ModelLogin[] getLogin() {
return login;
}
}
그리고 ModelLogin
:
public class ModelLogin {
private Object Key;
private Integer Response;
public Object getKey() {
return Key;
}
public Integer getResponse() {
return Response;
}
}
그리고 RequestInterface_Login
:
public interface RequestInterface_Login {
@GET("/courier.svc/login")
Call<JSONResponseLogin> getJSON(@Query("username") String username, @Query("password") String password);
}
충돌 나 :
java.lang.NullPointerException: storage == null
귀하가 올린 코드가 귀하의 코드 줄을 가리 키지 않으므로 전체 스택 트레이스를 넣으십시오. – jakubbialkowski