마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

Retrofit을 사용중인데, 서버에서 받아온 내용을 전부 출력하고 싶습니다.

0 추천

 

Retrofit client = new Retrofit.Builder().baseUrl("http://api.openweathermap.org").addConverterFactory(GsonConverterFactory.create()).build();

ApiInterface service = client.create(ApiInterface.class);
final Call<Repo> call = service.repo("appKey", Double.valueOf(lat), Double.valueOf(lot));
call.enqueue(new Callback<Repo>() {
    @Override
    public void onResponse(Response<Repo> response) {
        if (response.isSuccess()) {
            Repo repo = response.body();
         
            tem.setText(String.valueOf(repo.getMain().getTemp()-273));
        } else {

        }
    }

    @Override
    public void onFailure(Throwable t) {
    }
});

 

메인 소스가 이런식이고,

데이터가 제대로 넘어 온것을 확인하기 위해서, appKey와 변수값을 넘겨주고

서버에서 넘겨주는 전체적인 데이터를 찍어보고 싶습니다.

 

Log.d("test123",repo+"_[1]");
Log.d("test123",repo.toString()+"_[2]");
Log.d("test123",repo.getMain()+"_[3]");
Log.d("test123",repo.getMain().toString()+"_[4]");
Log.d("test123",repo.getMain().getTemp()+"_[5]");
Log.d("test_message",response.message()+"");
Log.d("test_code",response.code()+"");
Log.d("test_raw",response.raw()+"");
Log.d("test_headers",response.headers()+"");
Log.d("test_errorBody",response.errorBody()+"");
Log.d("test_body",response.body()+"");

 

이런식으로 테스트해보는데, 전체 데이터가 뜨지는 않네요 ㅠㅠ

전체 데이터는 아래와 같습니다

 

아래처럼 전체 데이터를 뜨게해서, 일단 데이터가 잘 넘어왔는지만 확인하려면 어떻게 하면될까요??

 

{
  "coord": {
    "lon": 127.05,
    "lat": 37.65
  },
  "weather": [
    {
      "id": 800,
      "main": "Clear",
      "description": "clear sky",
      "icon": "01d"
    }
  ],
  "base": "stations",
  "main": {
    "temp": 291.14,
    "pressure": 1014,
    "humidity": 14,
    "temp_min": 289.15,
    "temp_max": 293.15
  },
  "visibility": 10000,
  "wind": {
    "speed": 5.1,
    "deg": 320,
    "gust": 11.3
  },
  "clouds": {
    "all": 1
  },
  "dt": 1493194800,
  "sys": {
    "type": 1,
    "id": 8514,
    "message": 0.0148,
    "country": "KR",
    "sunrise": 1493152934,
    "sunset": 1493201850
  },
  "id": 1835847,
  "name": "Seoul-teukbyeolsi",
  "cod": 200
}

 

 

 

 

떡빵s (1,370 포인트) 님이 2017년 4월 26일 질문
떡빵s님이 2017년 4월 26일 수정

1개의 답변

+1 추천
 
채택된 답변

http://stackoverflow.com/questions/32965790/retrofit-2-0-how-to-print-the-full-json-response

제일 간단한건 gson 연동이네요

call.enqueue(new Callback<someList>() {
        @Override
        public void onResponse(Call<someList> call, Response<someList> response) {
            if (response.isSuccessful())
                Log.e("Success", new Gson().toJson(response.body()));
            else
                Log.e("unSuccess", new Gson().toJson(response.errorBody()));
        }

        @Override
        public void onFailure(Call<someList> call, Throwable t) {
            Log.e("onFailure", t.toString());
        }
    });

익명사용자 님이 2017년 4월 27일 답변
떡빵s님이 2017년 4월 27일 채택됨
와.... response.body() 해도 요상한 주소값같은거 떠서 뭔가 했더니.... Json으로 바뀌지 않은 내용이었나보군요 ㅠㅠ

많은 도움되었습니다 감사합니다^^
...