How to get string response from Retrofit2?

前端 未结 10 1498
时光取名叫无心
时光取名叫无心 2020-12-01 07:44

I am doing android, looking for a way to do a super basic http GET/POST request. I keep getting an error:

java.lang.IllegalArgumentException: Unable to creat         


        
10条回答
  •  無奈伤痛
    2020-12-01 07:55

    make sure its JsonObject not a JSONObject

    Call call = api.getJsonData(url);
        call.enqueue(new Callback() {
            @Override
            public void onResponse(Call call, Response response) {
                String str = response.body().toString();
                Log.e(TAG, "onResponse: " + str);
            }
    
            @Override
            public void onFailure(Call call, Throwable t) {
                Log.e(TAG, "onFailure: " + t.getMessage());
    
            }
        });
    

    By using JsonObject you can get any type of response in string format.

提交回复
热议问题