If in the process of use, do not need gson and other converters, but simply return jsonobject, then how to deal with it?
By reading source discovery, you can manipulate it by customizing the converter:
import retrofit.Call/*Retrofit 2.0*/public interfase ApiService{ @POST("/list") Call<JSONObject> loadRepo();}
Synchronous operation:
Callcall = service.loadRepo();call.excute()
Asynchronous Operation:
Call<JSONObject> call = service.loadRepo();call.enqueue(new Callback<JSONObject>(){ @Override publicvoidonResponse(Response<JSONObject> response){ //从response.body()中获取结果 } @Override publicvoidonFailure(Throwable t){ }});
Is that it? No.
Address: Https://github.com/brokge/Retrofit2.0-JSONCoverter
Select the appropriate version to add to the project. (Retrofit 2.0-beta2 and Retrofit 2.0-beta4 are processed differently)
- Gsonconverterfactory.create (Gson) change to Jsonconverterfactory.create ()
The complete code is as follows:
private static Retrofit Initretrofit () {okhttpclient httpClient = new Okhttpclient ();if (buildconfig. DEBUG) {Httplogginginterceptor logging = new Httplogginginterceptor ();Logging. SetLevel(Httplogginginterceptor. level. BODY);HttpClient = new Okhttpclient. Builder(). Addinterceptor(logging). Build();} return new Retrofit. Builder(). BaseUrl(Baseutil. Getapiurl()). Addconverterfactory(jsonconverterfactory. Create()). Client(httpClient). Build();}
Perhaps you are also interested in the following articles:
Android Retrofit Request string (non-JSON data)
Android Retrofit 2.0 Custom Jsonobject Converter