I'm trying to retrieve data from a third-party API but I'm having this issue down below:
Process: com.main.instareeldownloader, PID: 8483
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:225)
This is where I'm trying to retrieve data.
StringRequest request = new StringRequest(URL, response -> {
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
MainUrl mainUrl = gson.fromJson(response, MainUrl.class);
reeelUrl = mainUrl.getItems();
Log.e("Data",reeelUrl);
uri2 = Uri.parse(reeelUrl);
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri2);
videoView.requestFocus();
videoView.start();
}, error -> Toast.makeText(getContext(), "Not able to Fetch.", Toast.LENGTH_SHORT).show());
RequestQueue queue = Volley.newRequestQueue(getContext());
queue.add(request);
This is my MainUrl Model
String items;
//private MainReel items;
public MainUrl(String items) {
this.items = items;
}
public String getItems() {
return items;
}
public void setItems(String items) {
this.items = items;
}
@Override
public String toString() {
return "MainUrl{" +
"items='" + items + '\'' +
'}';
}
From the JSON try to retrieve this:
items -> video_versions -> url
I'm confused why an error is occurring for.