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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:57:09+00:00 2026-06-15T02:57:09+00:00

I’m trying to convert an object, and this object has an ArrayList object has

  • 0

I’m trying to convert an object, and this object has an ArrayList object has attribute and an integer.

But when i use to toString() on the JSON object I got pointers instead of the object:

{"class":"class model.ListResult","listVideo":["model.Video@706a4d1a","model.Video@52ec1f9e","model.Video@c0fe89a","model.Video@686fdca5","model.Video@7ff0a34","model.Video@78f6e005","model.Video@17eda64e","model.Video@73415727","model.Video@46c0fc8e"],"numberOfResult":109}

Here is the code for my class:

public class ListResult implements Serializable {

    private int numberOfResult;
    private ArrayList<Video> listVideo;

    /**
     * Constructor
     * 
     * @param allVideoNumber
     * @param listVideo2
     */
    public ListResult(int numberOfResult, ArrayList<Video> listVideo) {

        this.numberOfResult = numberOfResult;
        this.listVideo = listVideo;

    }

    public int getNumberOfResult() {
        return numberOfResult;
    }
    public void setNumberOfResult(int numberOfResult) {
        this.numberOfResult = numberOfResult;
    }
    public ArrayList<Video> getListVideo() {
        return listVideo;
    }
    public void setListVideo(ArrayList<Video> listVideo) {
        this.listVideo = listVideo;
    }

}

And my method call :

public String getListJson(boolean escape, int from, int number, String order, String by, ArrayList<Category> listCategory) throws Exception {

    //get list of video
    ArrayList<Video> listVideo = dbVideo.getAll(from, number, order, by, listCategory);

    JSONObject jsObject = new JSONObject(new ListResult(dbVideo.getAllVideoNumber(listCategory), listVideo));

    if(escape) {
        String  r;

        r = jsObject.toString();
        r = r.replace("\\", "\\\\");
        r = r.replace("'", "\\'");

        return r;

    }

    return jsObject.toString();

}
  • 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-15T02:57:10+00:00Added an answer on June 15, 2026 at 2:57 am

    It’s probably because the toString() method calls all the other objects’ toString() method and those are not overridden. That gives the effect that they will print their name (the class name) and the “address” that they are located at in the JVM. One way to solve this would be to override said method and give it some better implementation. Although i don’t know if this is a good idea and perhaps you should have a look at serialization instead if you want to do this a lot. But for this simple case i think a simple override of the toString() method should suffice if it doesn’t break some other functionality.
    What i mean is something along these lines:

    class Video {
        public String toString() {
            return this.title + " " + this.yearOfRelease;
        }
    }
    

    Where you perhaps need to edit this to be the proper JSON output.

    Although i should add that im not certain about this and just guessing how the toString() method for JSONObject works. It could be something entirely different. But it’s worth a shot!

    Edit: After looking a little at the JSONObject docs: http://www.json.org/javadoc/org/json/JSONObject.html
    It would seem that you should use the put() method to insert your elements, and then use the toString() method. Ie, you would need to loop over all elements in the list and add them one by one. Or the override of toString() in your Video class might do the work.

    Edit2: Furthermore it would seem that http://www.json.org/javadoc/org/json/JSONObject.html#put%28java.lang.String,%20java.util.Collection%29 is of interest to you, it will take a Collection which your list should be, that could perhaps solve things.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
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
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
This could be a duplicate question, but I have no idea what search terms
i got an object with contents of html markup in it, for example: string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.