Getting simple JSON object response using Retrofit library

后端 未结 8 2062
感动是毒
感动是毒 2020-12-17 17:59

I have a web query with JSON response as:

{
    \"status\":true,
    \"result\":
      {
        \"id\":\"1\",
        \"name\":\"ABC 1\",
        \"email\":         


        
8条回答
  •  忘掉有多难
    2020-12-17 18:26

    The answers seam kinda old and for Retrofit 1, if you are using Retrofit 2 and don't want to use a converter you have to use ResponseBody.

    @GET("/stockers/login")
    public void login(
        @Query("email") String email,
        @Query("password") String password,
        Callback callback);
    

    And then in your callback in the onResponse method call string on the body and create a JSONObject from it.

    if(response.isSuccessful())
        JSONObject json = new JSONObject(response.body().string());
    

提交回复
热议问题