Reputation: 3254
I'm trying to parse a json object that is int when it's good, and string when it's not, here's an example :
id: "11271",
title: "Top Gun: An IMAX 3D Experience",
year: 1986,
mpaa_rating: "PG",
runtime: 110,
release_dates: {
theater: "2013-02-08",
dvd: "1998-10-20"
},
ratings: {
critics_rating: "Rotten",
critics_score: 50,
audience_rating: "Upright",
audience_score: 48
},
id: "771270981",
title: "Identity Thief",
year: 2013,
mpaa_rating: "R",
runtime: "",
release_dates: {
theater: "2013-02-08"
},
ratings: {
critics_score: -1,
audience_score: 97
},
the problem in question is the "runtime"
the cause of problem is : "java lang NumberFormatException : Invalid double : ""
and you sure know that with Gson you need to create a class that goes like this :
private int runtime;
public void setRuntime(int runtime) {
this.runtime = runtime;
}
public int getRuntime() {
return runtime;
}
}
How can i trick the program, know that it's not my API.
Upvotes: 1
Views: 418
Reputation: 18863
By changing private int runtime;
to private String runtime;
Depending what you do afterwards, you can check if its a int, if it is , deal with it as int, else deal with it as String.
Upvotes: 1