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 obtain an element width using the following code just before
I am trying to obtain class information on a field inside a model, when
I've been trying to obtain the Driver class for JDBC connection to MySQL. The
I am trying to obtain a list of assets (via JSON) inside of a
I am trying to obtain the document inside a frame. The following does not
i have been having this trouble when trying to obtain json data. lets say
I am trying to obtain in a Map the properties of the following Entity:
I am trying to implement a JSON-RPC solution, using a server connector object which
I have to following response from a server: page:{result:ok,id_photo:36782710} .And I'm trying to obtain
I am trying to obtain the value part of this syntax: [name:value] I got

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.