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

  • SEARCH
  • Home
  • 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 7555797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:42:12+00:00 2026-05-30T11:42:12+00:00

I am having trouble to parse a JSON string. The JSON is given below:

  • 0

I am having trouble to parse a JSON string. The JSON is given below:

[
  {
    "firstname": "firstname",
    "lastname": "lastname",
    "address": "address",
    "images": [
      {
        "image": {          
          "url": "url",
          "id": "id"
        }
      },
      {
        "image": {
          "url": "url",
          "id": "id"
        }
      }
    ]
  },
  {
    "firstname": "firstname",
    "lastname": "lastname",
    "address": "address",
    "images": [
      {
        "image": {          
          "url": "url",
          "id": "id"
        }
      },
      {
        "image": {
          "url": "url",
          "id": "id"
        }
      }
    ]
  }
]

I have defined the required Beans as:
Person.java

public class Person implements Serializable {
    private static final long serialVersionUID = 38L;

    private String firstname;
    private String lastname;
    private String address;
    private Image[] images;

    public Person() {

    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Image[] getImages() {
        return images;
    }

    public void setImages(Image[] images) {
        this.images = images;
    }
}

Image.java:

public class Image implements Serializable {
    private static final long serialVersionUID = 39L;

    private String url;
    private String id;

    public Image() {

    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }       
}

Now I am parsing the JSON string as:

Gson gson = new Gson(); 
Person[] persons = (Person[])gson.fromJson(jsonString, Person[].class);

Now if I print

System.out.println(persons[0].getFirstname());
System.out.println(persons[0].getLastname());
System.out.println(persons[0].getAddress());

it is printing the corresponding values. Also:

persons[0].getImages() is not null;
persons[0].getImages()[0] is not null;

but

persons[0].getImages()[0].getUrl() is null;
persons[0].getImages()[0].getId() is null;

I am unable to understand what I am doing wrong? Is there any mistake I made in defining the beans?

I really appreciate your help.

  • 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-30T11:42:14+00:00Added an answer on May 30, 2026 at 11:42 am

    I assume that you shouldn’t specify name of object inside the array. Replace

    "image": {          
        "url": "url",
        "id": "id"
    }
    

    with simply

    {          
        "url": "url",
        "id": "id"
    }
    

    In case you want to parse specified JSON String you should have differen Object structure:

    public class Person implements Serializable {
        private static final long serialVersionUID = 38L;
    
        private String firstname;
        private String lastname;
        private String address;
        private Foo[] images;
    }
    
    public class Foo{
        private Image image;
    }
    public class Image implements Serializable {
        private static final long serialVersionUID = 39L;
    
        private String url;
        private String id;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a json file with unicode characters, and i'm having trouble to parse
I'm having trouble implementing a script which should parse a json string from a
I'm trying to parse JSON in android but am having trouble with accessing sub
I have managed to parse ok. But now I am having trouble getting the
Sometimes I need to parse string that is CSV, but I am having trouble
I'm using DOM to parse an xml file. And I am having trouble catching
Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder
I having trouble in dividing the HTML frames. I have been using the following
Im having trouble reading from a CSV file final String DELIMITER = ,; Scanner
I have a Spring 3.1 MVC project, and I'm having trouble deserializing a request

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.