title: How to convert the json object response from retrofit success response?
body: <p>I have worked with retrofit file upload. Here by using <code>system.out.println</code> I can track the response body. But can't convert the response to <code>JSON</code> object.
  I hereby write my code. Kindly please let me know how do I parse and get the string value using retrofit success message and failure message. </p>
  
  <h2>ApiConfig:</h2>
  
  <pre><code>public interface ApiConfig {
  
      @Multipart
      @POST("general/Candidate/fileUpload")
      Call&lt;ResponseBody&gt; upload(
              @Header("Authorization") String authorization,
              @PartMap Map&lt;String, RequestBody&gt; map,
              @Part("id") RequestBody id,
              @Part("fileCount") RequestBody fileCount,
              @Part("fileType") RequestBody fileType,
              @Part("platform") RequestBody platform,
              @Part("externalID") RequestBody externalID);
  
  
  }
  </code></pre>
  
  <h2>ServiceGenerator:</h2>
  
  <pre><code>public class ServiceGenerator {
  
      public static final String API_BASE_URL = "http://104.239.173.64/peoplecaddie-api/";
  
      private static Retrofit retrofit = null;
      private static OkHttpClient httpClient = new OkHttpClient.Builder()
              .readTimeout(60, TimeUnit.SECONDS)
              .connectTimeout(60, TimeUnit.SECONDS)
              .build();
  
      private static Retrofit.Builder builder =
              new Retrofit.Builder()
                      .baseUrl(API_BASE_URL)
  
                      .addConverterFactory(GsonConverterFactory.create(new Gson()));
  
      public static &lt;S&gt; S createService(Class&lt;S&gt; serviceClass) {
          Retrofit retrofit = builder.client(httpClient).build();
          return retrofit.create(serviceClass);
      }
  
  }
  </code></pre>
  
  <h2>uploadFile1:</h2>
  
  <pre><code>private void uploadFile1(Uri fileUri) {
      progressDialog.show();
      ApiConfig service =
              ServiceGenerator.createService(ApiConfig.class);
  
  
  
      File file = FileUtils.getFile(this, fileUri);
      RequestBody requestFile =
              RequestBody.create(MediaType.parse("multipart/form-data"), file);
      Map&lt;String, RequestBody&gt; map = new HashMap&lt;&gt;();
      map.put("fileContent0\"; filename=\"" + file.getName() + "\"", requestFile);
      MultipartBody.Part body =
              MultipartBody.Part.createFormData("fileContent0", file.getName(), requestFile);
      String idStr = "1743";
      String fileCountStr = "1";
      String fileTypeStr = "SAMPLE";
      String platformStr = "Android";
      String externalIDStr = "portpolio";
      RequestBody idReq =
              RequestBody.create(
                      MediaType.parse("multipart/form-data"), idStr);
      RequestBody fileCountReq =
              RequestBody.create(
                      MediaType.parse("multipart/form-data"), fileCountStr);
      RequestBody fileTypeReq =
              RequestBody.create(
                      MediaType.parse("multipart/form-data"), fileTypeStr);
      RequestBody platformReq =
              RequestBody.create(
                      MediaType.parse("multipart/form-data"), platformStr);
      RequestBody externalIDReq =
              RequestBody.create(
                      MediaType.parse("multipart/form-data"), externalIDStr);
      // finally, execute the request
      Call&lt;ResponseBody&gt; call = service.upload("817b6ce98fd759e7f148b948246df6c1", map, idReq, fileCountReq, fileTypeReq, platformReq, externalIDReq);
      call.enqueue(new Callback&lt;ResponseBody&gt;() {
          @Override
          public void onResponse(Call&lt;ResponseBody&gt; call,
                                 Response&lt;ResponseBody&gt; response) {
              try {
                  System.out.println("Rrespppppp---&gt;"+response.body().string());
                  Log.e("response", "response------------------&gt;" + response.body().string());
                  JSONObject profileFileUploadResponse = new JSONObject(String.valueOf(response.body()));
                  Log.e("retro", "retroFileResp------------------&gt;" + profileFileUploadResponse);
              } catch (IOException e) {
                  e.printStackTrace();
              } catch (JSONException e) {
                  e.printStackTrace();
              }
  
          }
  
          @Override
          public void onFailure(Call&lt;ResponseBody&gt; call, Throwable t) {
              Log.e("Upload error:", t.getMessage());
          }
      });
  
  }
  </code></pre>
  
  <p>Here upload file method I can track the response using. This works fine.</p>
  
  <pre><code> System.out.println("Rrespppppp---&gt;"+response.body().string());
  </code></pre>
  
  <p>But while try to convert the <code>JSON</code> Object it will not work the error code is below. And please let me know how do i parse and get the success and failure response value using this code.</p>
  
  <pre><code>Log.e("response", "response------------------&gt;" + response.body().string());
  JSONObject profileFileUploadResponse = new JSONObject(String.valueOf(response.body()));
  Log.e("retro", "retroFileResp------------------&gt;" + profileFileUploadResponse);
  </code></pre>
  
  <p>Thanks in Advance.</p>