Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
James Kafir
Greenhorn
+ Follow
1
Posts
1
Threads
0
Cows
since Jan 13, 2010
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
Ranch Hand Scavenger Hunt
Number Posts (1/100)
Number Threads Started (1/100)
Number Cows Received (0/5)
Number Likes Received (0/10)
Number Likes Granted (0/20)
Set bumper stickers in profile (0/3)
Report a post to the moderators (0/1)
Edit a wiki page (0/1)
Create a post with an image (0/2)
Greenhorn Scavenger Hunt
First Post
Number Posts (1/10)
Number Threads Started (1/10)
Number Likes Received (0/3)
Number Likes Granted (0/3)
Set bumper stickers in profile (0/1)
Set signature in profile
Search for a post/thread (0/3)
Set a watch on a thread
Save thread as a bookmark
Create a post with an image (0/1)
Recent posts by James Kafir
struts2 json problem
Hi all,
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?
show more
14 years ago
Struts