Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8592507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:45:58+00:00 2026-06-11T23:45:58+00:00

I’m trying to parse the JSON data from the Rotten Tomatoes API using GSON

  • 0

I’m trying to parse the JSON data from the Rotten Tomatoes API using GSON in Android. I can get some of it parsed, but I seem to be having trouble with the arrays inside of my base result object.

Here is my “MovieObject” class:

package ---;

import com.google.gson.annotations.SerializedName;

import java.util.List;

public class MovieObject {

public List<Rating> ratings; //You are a problem

    @SerializedName("id")
    public String id;

    @SerializedName("title")
    public String title;

    @SerializedName("year")
    public int year;

    @SerializedName("mpaa_rating")
    public String mpaaRating;

    @SerializedName("runtime")
    public int runtime;

    @SerializedName("critics_consensus")
    public String criticsConsensu;

    @SerializedName("synopsis")
    public String synopsis;

    @SerializedName("studio")
    public String studio;
}

I can successfully pull fields such as title, id and year but can not access fields in my Rating class (public List<Rating> ratings)

Here is the Rating class:

package ---

import com.google.gson.annotations.SerializedName;

public class Rating {

    @SerializedName("critics_rating")
    public String criticsRating;

    @SerializedName("critics_score")
    public int criticsScore;

    @SerializedName("audience_rating")
    public String audienceRating;

    @SerializedName("audience_score")
    public int audienceScore;
}

Here is some excerpts from my activity related to how I’m trying to get the data. Which works, for the most part.

InputStream source = retrieveStream(url);

        Gson gson = new Gson();

        Reader reader = new InputStreamReader(source);

        MovieObject mObject = gson.fromJson(reader, MovieObject.class); //Expected BEGIN_ARRAY but was BEGIN_OBJECT instead. Something to do with the Rating object I believe.

        Toast.makeText(this, mObject.title, Toast.LENGTH_SHORT).show();
        Toast.makeText(this, mObject.synopsis,Toast.LENGTH_SHORT).show();

The problem arises when I try to do something like this:

List<Rating> ratings = mObject.ratings;
for (Rating rating : ratings) {
    Toast.makeText(this, rating.criticsScore,Toast.LENGTH_SHORT).show();
}

The error shown is:

Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 28 column 362

If I comment out the part in MovieObject where I declare the Ratings variable… things work. So that seems to be the issue. BUT I’m not sure how to get around that. Would it be easier to just do native Android JSON parsing instead of trying to use GSON? Or mess with Jackson?

For reference, here is the api viewer for the Rotten Tomatoes response: http://jsonviewer.stack.hu/#http://api.rottentomatoes.com/api/public/v1.0/movies/770672122.json?apikey=vg2cj5tgqmbkkxz2vgyxqyh9

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:46:00+00:00Added an answer on June 11, 2026 at 11:46 pm

    Well, that’s because the ratings field is NOT an array:

    "ratings": {
        "critics_rating": "Certified Fresh",
        "critics_score": 99,
        "audience_rating": "Upright",
        "audience_score": 91
      },
    

    It’s an object. So, just declare it as public Ratings ratings;

    abridged_directors, for example, IS a list:

    "abridged_directors": [
        {
          "name": "Lee Unkrich"
        }
      ],
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.