how to create a JSON object in action class of JAVA

Posted by Jugal on Stack Overflow See other posts from Stack Overflow or by Jugal
Published on 2009-06-03T11:48:10Z Indexed on 2010/12/29 5:54 UTC
Read the original article Hit count: 322

Filed under:
|
|

I want to create a JSON object. I have tried the following

myString=new JSONObject().put("JSON", sampleClass).toString();

but mystring gives me {"SampleClass@170f98"}.

I also tried the following

 XStream xsStream=new XStream(new JsonHierarchicalStreamDriver());
 SampleClass sampleClass=new SampleClass(userset.getId(),userset.getUsername());
 myString=xsStream.toXML(sampleClass);

It works but when i use getJSON in javascript to get myString it does not work.

© Stack Overflow or respective owner

Related posts about java

Related posts about JSON