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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:50:22+00:00 2026-05-13T17:50:22+00:00

I am trying to obtain JSON object in the following code. The problem is,

  • 0

I am trying to obtain JSON object in the following code. The problem is, I am getting the object twice. Any help is appreciated.

public class MenuAction {
    private String ms;
    private List<Menu> menus;

    public String getMs() {
        return ms;
    }

    public void setMs(String ms) {
        this.ms = ms;
    }

    //execute method
    public String execute(){
        menus = new ArrayList<Menu>();
        Menu af = new Menu();
        af.setText("A Folder");
        af.setCls("folder");
        af.setLeaf(false);
        af.setId(10);
        menus.add(af);

        List<Menu> aList = new ArrayList<Menu>();
        Menu menu;
        menu = new Menu();
        menu.setText("A Child 1");
        menu.setCls("file");
        menu.setLeaf(true);
        menu.setId(11);
        aList.add(menu);
        menu = new Menu();
        menu.setText("A Child 2");
        menu.setCls("file");
        menu.setLeaf(true);
        menu.setId(12);
        aList.add(menu);
        af.setChildren(aList);

        JSONArray ja = JSONArray.fromObject(menus);
        try {
            ms = ja.toString();
        } catch (Exception e){
            ms = "ss";
        }
        System.out.println(ms);
        return Action.SUCCESS;
    }
} 

what it prints is the following.

[{"children":[{"children":[],"cls":"file","id":11,"leaf":true,"text":"A Child 1"},{"children":[],"cls":"file","id":12,"leaf":true,"text":"A Child 2"}],"cls":"folder","id":10,"leaf":false,"text":"A Folder"}]

[{"children":[{"children":[],"cls":"file","id":11,"leaf":true,"text":"A Child 1"},{"children":[],"cls":"file","id":12,"leaf":true,"text":"A Child 2"}],"cls":"folder","id":10,"leaf":false,"text":"A Folder"}]

Basically it is producing same json string twice. Why is it doing so?

  • 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-13T17:50:22+00:00Added an answer on May 13, 2026 at 5:50 pm

    Perhaps you’re calling the MenuAction twice. Check your form/ajax request.

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

Sidebar

Related Questions

I am trying to use an http request to google maps to obtain the
I'm trying to obtain the base URL (hostname) of the server in which my
I am trying to obtain the absolute path to the currently running script on
I'm trying to obtain the size of a file before I download it. I
Background I'm trying to get obtain a unique identifier out of a computer and
I trying to use command Explain to obtain the query time of my mySql
I'm trying to wrap all <p> from a div in a sub-div ; the
I was able to generate python bindings for a camera library using SWIG and
I have a WCF Service set up on my web site with a service.
I have a DataGridView that displays data from a MS Access database. I'm using

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.