File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts and JSON Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts and JSON" Watch "Struts and JSON" New topic
Author

Struts and JSON

Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183

Folks,

I'm not sure if this post goes in here but since it looked like a struts rendering issue that I didn't understand right I have posted it here.

I use struts 2 and have the following code in the action class



And the jsp page has the following call


The issues looks like the property tag is processes the data. Is there a way to prevent the property tag from doing this.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Don't know whether this will works for you, but give it a try,
Just escape the single quote " ' ", while creating JSON object like,



[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
Thanks Sagar.
Thats the problem. I would have escaped it in the struts code but unfortunately I am using a JSONObject.



Is there a way to escape it in the property tag ?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Jay Abrahm wrote:I would have escaped it in the struts code but unfortunately I am using a JSONObject.

Hmm, I thought that JSONObject class is developed by you as a helper class.
Maybe, we can repleace that JSON string with "\'", like




Jay Abrahm wrote:
Is there a way to escape it in the property tag ?

Never used Struts 2, but while exploring it <s:property> tag, I found something useful, its "escape" attribute itself, but its default value is "true", so don't think will it make any difference or not !!

Still use it and make its default value as a "false"

Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183

Issue resolved. Thanks and that was quick. I didn't notice your post coming in.

Yes, escape="false" did fix the escape for double quotes issue.



I still have another issue with the dojo not accepting the JSON (commented in the alerts above) but I guess the moderator might hack me down if I try to use this forum for that
Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
Just a side note. Even the JSON to dojo is working now fine. The nested object should also be a JSONObject.

I beginning to like JSON !!

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts and JSON
 
Similar Threads
struts2+json mapping issue...
JSON problem
Struts2 mapping query
how to, JSON data
need help building a =hiearchical= JSON object