I'm trying to get just string request but it's give error like this
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
And my API output is like this :
{
"status": true,
"message": "Video uploaded successfully!",
"data": {
"video_name": "674631516178278_abc2.mp4",
"video_thumbnail": "674631516178278_thumb0017.jpg"
}
}
Code for response :
@Override
public void onResponse(Call<String> call, Response<String> response) {
try {
if (response.body() != null)
Log.e("UploadResponse>>>", response.body());
layoutUpload.setVisibility(View.GONE);
if (file.exists()) {
file.delete();
thumb.delete();
}
} catch (Exception e) {
e.printStackTrace();
layoutUpload.setVisibility(View.GONE);
if (file.exists()) {
file.delete();
thumb.delete();
}
}
}
Try like this
@Override
public void onResponse(Call<ResponseBody> call, Response< ResponseBody > response) {
try {
if (response.body() != null)
Log.e("UploadResponse>>>", response.body());
layoutUpload.setVisibility(View.GONE);
if (file.exists()) {
file.delete();
thumb.delete();
}
} catch (Exception e) {
e.printStackTrace();
layoutUpload.setVisibility(View.GONE);
if (file.exists()) {
file.delete();
thumb.delete();
}
}
}
.addConverterFactory(ScalarsConverterFactory.create()) .addxxxx
Error say's you want to get result in String body. If you want to do this, Just add ScalarsConverterFactory.create() in your Retrofit.Builder.
public static Retrofit getClient() {
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(getBaseUrl())
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
return retrofit;
}
Use retrofit Implementation in app level build.gradle.
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With