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 6142061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:20:12+00:00 2026-05-23T18:20:12+00:00

Good day people. I have this JSON result here http://pastebin.com/9psYCfGj . And I want

  • 0

Good day people.
I have this JSON result here http://pastebin.com/9psYCfGj.
And I want to get the first 2 backdrops (Start at line 607).

So I want to get the URL of the first backdrop with the size of w1280 (line 639)
And the URL of the second backdrop with the size of w1280 (line 680)

How would I only get these two URLs

Thanks
Tom

  • 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-05-23T18:20:13+00:00Added an answer on May 23, 2026 at 6:20 pm

    The example JSON in the original question was over 800 lines. Here’s a trimmed version that retains the same structure (but is still longish at 50 lines).

    [
        {
            "id": 17529,
            "name": "True Grit",
            "posters": [
                {
                    "image": {
                        "type": "poster",
                        "size": "original",
                        "height": 1500,
                        "width": 1000,
                        "url": "http://cf1.imgobject.com/posters/0be/4db5f8e65e73d67a840070be/true-grit-original.jpg",
                        "id": "4db5f8e65e73d67a840070be"
                    }
                },
                {
                    "image": {
                        "type": "poster",
                        "size": "w154",
                        "height": 211,
                        "width": 154,
                        "url": "http://cf1.imgobject.com/posters/284/4d559bb87b9aa15cf6001284/true-grit-w154.jpg",
                        "id": "4d559bb87b9aa15cf6001284"
                    }
                }
            ],
            "backdrops": [
                {
                    "image": {
                        "type": "backdrop",
                        "size": "w1280",
                        "height": 720,
                        "width": 1280,
                        "url": "http://cf1.imgobject.com/backdrops/900/4d33ccea7b9aa177db007900/true-grit-w1280.jpg",
                        "id": "4d33ccea7b9aa177db007900"
                    }
                },
                {
                    "image": {
                        "type": "backdrop",
                        "size": "w1280",
                        "height": 720,
                        "width": 1280,
                        "url": "http://cf1.imgobject.com/backdrops/01f/4c90088b5e73d61ee900001f/true-grit-w1280.jpg",
                        "id": "4c90088b5e73d61ee900001f"
                    }
                }
            ]
        }
    ]
    

    As already suggested, a simple approach would be to use Gson to deserialize the JSON into a Java data structure, and then iterate through the Java structure to select the target data. Alternatively, there do exist at least two Java-to/from-JSON libraries that allow xpath-like selection queries to simply pull out just the target data, but they’re very slow compared to other Java libraries for reading JSON, and they don’t yet have a lot of community use and support, so I wouldn’t recommend them. At any rate, whether using Gson or any other Java-to/from-JSON library, you’d do well to decide on selection criteria other than line number.

    Assuming that the selection goal includes the URLs of the first two backdrops with size w1280, following is an example of using Gson to accomplish it.

    The situation is complicated a little in that the JSON structure wraps the single response object in an array, and wraps each of the image objects in an array. So, the following Java data structure simply matches this structure exactly.

    import java.io.FileReader;
    import java.lang.reflect.Type;
    import java.util.List;
    
    import com.google.gson.Gson;
    import com.google.gson.reflect.TypeToken;
    
    public class Foo
    {
      public static void main(String[] args) throws Exception
      {
        Gson gson = new Gson();
        Type movieListType = new TypeToken<List<Movie>>() {}.getType();
        List<Movie> movies = gson.fromJson(new FileReader("input.json"), movieListType);
    
        // movies has just one Movie
        Movie movie = movies.get(0);
    
        // Find the first two Backdrop URLs with size = w1280
        int foundCount = 0;
        for (Backdrop backdrop : movie.backdrops)
        {
          if ("w1280".equals(backdrop.image.size))
          {
            System.out.println("URL Found: " + backdrop.image.url);
            foundCount++;
            if (foundCount == 2)
            {
              break;
            }
          }
        }
      }
    }
    
    class Movie
    {
      int id;
      String name;
      List<Poster> posters;
      List<Backdrop> backdrops;
    }
    
    class Poster
    {
      Image image;
    }
    
    class Backdrop
    {
      Image image;
    }
    
    class Image
    {
      String type;
      String size;
      int height;
      int width;
      String url;
      String id;
    }
    

    Note: Since Poster and Backdrop have the same exact structure (they just contain an Image reference), they could easily be merged into a single data type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good Day wonderful computer people of the planet Earth! Here is the struct in
Good day. I could really use your help on this one. I have a
Very specific question but we have some good Ada people here so I would
Good day! I just want to ask if an InfoBubble can have a listener.
Good Day, Can someone confirm what was said at the bottom of this post
Good day, I have a class that implements the LoaderCallbacks, and hence have the
Good day I have a custom TextBox that has a IndicatorTextBox.ui.xml file as well
Good day, I have like 15 images I need to be buttons. I have
Good day, all. I know that this is a pretty basic question in terms
Good Day, I have a simple working routine in Perl that swaps two words:

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.