how to send JSONObject into retrofit API call android

后端 未结 1 730
时光取名叫无心
时光取名叫无心 2020-12-20 19:52

I have implemented first time retrofit in my android code and facing follwing issues

getting following error : java.lang.IllegalArgumentException

相关标签:
1条回答
  • 2020-12-20 20:24

    You are using the Android internal Json APIs. You need to use Gson's classes instead.

    Call<JsonObject> sendLocation(@Body JsonObject jsonObject);
    

    Hence the import statement

    import com.google.gson.JsonObject;
    

    Another error is passing the Callback as a parameter to the request

    Call<JsonObject> call = apiService.sendLocation(jsonObject);
    call.enqueue(new Callback<JsonObject>() {
       @Override
       public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
          Log.d("response","Getting response from server : "+response);
       }
    
       @Override
       public void onFailure(Call<JsonObject> call, Throwable t) {
          Log.d("response","Getting response from server : "+t);
       }
    });
    
    0 讨论(0)
提交回复
热议问题