0

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

this is a my logcat error

2 Answers 2

1

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];
Sign up to request clarification or add additional context in comments.

3 Comments

De Clippelit's working but how i can change your last line code.i mean,at the moment i can get only first item,but i want to check all my first,in json has 3 item.
I'm not sure what you mean. Do you want to get all JsonModel objects from the array? You can get them all individually in a for-loop over the array.
i updated my code but not working @Inneke De Clippel
0

Try this code:

res1 = gson.fromJson(SpleshScreen.my_json, JsonModel[].class);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.