I know json object starts with { string starts with ". I checked multiple times, data types of each and every field are matching with json response.
I tried same code with
- Retrofit
- Async HTTP Client
I failed in both cases.
I also checked multiple links, but no success. Few links:
Android code:
Type type = new TypeToken<AuditionResponse>() {
}.getType();
AuditionResponse auditionResponse = null;
try {
String response = new String(responseBody, "UTF-8");
System.out.println("-- response = " + response);
auditionResponse = new Gson().fromJson(response, type);
} catch (Exception e) {
e.printStackTrace();
}
Response POJO
public class Response {
String message;
public Response(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
AuditionResponse POJO
public class AuditionResponse extends Response {
private List<Project> data;
public AuditionResponse(String message, List<Project> data) {
super(message);
this.data = data;
}
public List<Project> getData() {
return data;
}
public void setData(List<Project> data) {
this.data = data;
}
}
Project POJO
public class Project implements Serializable {
private String id;
private String user_id;
private String name;
private String type;
private String desc;
private String location;
private String country_id;
private String state_id;
private String city_id;
private String roleCount;
private String applicationCount;
private String castingDate;
private String shootDate;
private String industry;
private String casting_director;
private String director;
private String same_location_actor_can_apply;
private String is_paid;
private String status;
private String created;
private String modified;
}
Json response:
{
"message": "",
"data": [
{
"id": "284",
"user_id": "7393",
"name": "Indo-American film.",
"type": "1",
"desc": "Soni , a convicted former police officer, serving an unjust four year sentence for\r\nmanslaughter, is haunted by a past that has left her embittered and cynical. Her former boss,\r\nKalpana (Female, 32), IPS, feels a sense of guilt for not backing Soni during her trial, and compensates\r\nby securing her release for a sting operation initially conceived by Soni herself.!\r\nSetting aside their difference of opinions, they agree to embark upon the mission together, but\r\nthings get off to a rough start, when Soni breaks protocol, jeopardizing the legitimacy of the operation.\r\nThe incident uncovers an intense clash of ideas.",
"location": "Delhi",
"country_id": "India",
"state_id": "Delhi",
"city_id": "Central Delhi",
"roleCount": "6",
"applicationCount": null,
"castingDate": "2016-12-31",
"shootDate": "1970-01-01",
"industry": "0",
"casting_director": "Trishaan Csa",
"director": "Undisclosed ",
"same_location_actor_can_apply": "0",
"is_paid": "1",
"status": "1",
"device": "Web",
"created": "2016-12-22 09:11:00",
"modified": "2016-12-23 12:59:00"
},
{
"id": "283",
"user_id": "21193",
"name": "Romantic fiction show ",
"type": "3",
"desc": "A weekly romantic fiction show to be aired on a popular channel. Looking for actors to play lead roles. ",
"location": "mumbai ",
"country_id": "India",
"state_id": "Maharashtra",
"city_id": "",
"roleCount": "2",
"applicationCount": null,
"castingDate": "2017-01-01",
"shootDate": "1970-01-01",
"industry": "0",
"casting_director": "Jigna ",
"director": "Undisclosed ",
"same_location_actor_can_apply": "0",
"is_paid": "1",
"status": "1",
"device": null,
"created": "2016-12-21 09:42:00",
"modified": "2016-12-21 09:43:00"
},
{
"id": "282",
"user_id": "21193",
"name": "T.v show with a prominent channel ",
"type": "3",
"desc": "Its an undisclosed t.v show with a prominent channel, the story revolves around Punjabi culture .Looking for child actors to play lead and supporting roles. It is an continuity track for 8-10 months. ",
"location": "mumbai ",
"country_id": "India",
"state_id": "Maharashtra",
"city_id": "",
"roleCount": "3",
"applicationCount": null,
"castingDate": "2016-12-30",
"shootDate": "1970-01-01",
"industry": "0",
"casting_director": "Jigna ",
"director": "Undisclosed",
"same_location_actor_can_apply": "0",
"is_paid": "0",
"status": "1",
"device": null,
"created": "2016-12-21 08:02:00",
"modified": "2016-12-21 08:07:00"
},
{
"id": "280",
"user_id": "26727",
"name": "Pal Pal Dil Ke Paas",
"type": "1",
"desc": "The tradition of launching the sons of Deol\u00e2\u20ac\u2122s with a romantic film is being continued with Pal Pal Dil Ke Paas.Actor Sunny Deol is once again donning the director\u00e2\u20ac\u2122s hat, and this time he is all set to launch his son Karan Deol as the hero. The team is in Hunt for the cast. This is a golden opportunity for all you young actors out there to enter the world of Bollywood",
"location": "Mumbai\/ Delhi ",
"country_id": "India",
"state_id": "Maharashtra",
"city_id": "",
"roleCount": "1",
"applicationCount": null,
"castingDate": "2016-12-30",
"shootDate": "1970-01-01",
"industry": "0",
"casting_director": "Henna ",
"director": "Sunny Deol ",
"same_location_actor_can_apply": "0",
"is_paid": "1",
"status": "1",
"device": null,
"created": "2016-12-14 06:49:00",
"modified": "2016-12-14 06:54:00"
}
Exception:
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:224)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:852)
at com.google.gson.Gson.fromJson(Gson.java:801)
at com.actorsapply.actor.auditions.AuditionsFragment$1.onSuccess(AuditionsFragment.java:105)
//line 105 -- auditionResponse = new Gson().fromJson(response, type);
at com.loopj.android.http.AsyncHttpResponseHandler.handleMessage(AsyncHttpResponseHandler.java:351)
at com.loopj.android.http.AsyncHttpResponseHandler$ResponderHandler.handleMessage(AsyncHttpResponseHandler.java:510)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5459)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:213)
... 12 more
I guess you should use such response model: