Reputation: 349
I'm fairly new to JSON parsing , I'm using the GJson library and ran into this problem.
I'm trying to parse this JSON reponse:
This is a my model class:
public class JsonModel {
public int posterId ;
public String title ;
public String descraption ;
public String category ;
public String director ;
public String written ;
public String stars ;
public String georgia_time ;
public String wold_time ;
public String ipone_5 ;
public String ipone_5_blur ;
public String ipone_4 ;
public String ipone_4_blur ;
public String youtube ;
public String MovieFbID ;
public String imdb ;
public Cinemas cinemas ;
}
class Cinemas{
public List <Cinema> Cinemaname;
}
class Cinema{
public String cinemaName ;
public List<info> info ;
}
class info{
public String time;
public String hole ;
public String start_time ;
public String end_time ;
}
And i deserialize my json like this
try {
Gson gson = new Gson();
JsonModel[] res1 = gson.fromJson(SpleshScreen.my_json, JsonModel[].class);
JsonModel jsonModel = new JsonModel();
for (int i = 0; i < res1.length; i++) {
ServerItems objItem = new ServerItems();
objItem.setImage(imageurl+jsonModel.ipone_4);
Log.e("imageee", objItem.getImage());
arrayOfList.add(objItem);
}
I have a error in last line a my code
Upvotes: 0
Views: 813
Reputation: 1026
As you can see, the first character of the json is [
. This is the character for the start of an array. When you deserialize the json, you tell Gson you want to get an object, while what Gson finds is an array. So what you want to change in your code is this:
JsonModel[] res1 = gson.fromJson(SpleshScreen.my_json, JsonModel[].class);
After that you can get the first one like this:
JsonModel jsonModel = res1[0];
Upvotes: 1
Reputation: 159
Try this code:
res1 = gson.fromJson(SpleshScreen.my_json, JsonModel[].class);
Upvotes: 0