Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSON to XML Conversion  RSS feed

 
vivek dhiman
Ranch Hand
Posts: 153
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have one JSON file and task is to convert into XML. Attached is my java file through, Getting an error at line 30 Exception in thread "main" java.lang.NoSuchMethodError: nu.xom.Serializer.getEncoding()Ljava/lang/String;. Please check.



Thanks
 
g tsuji
Ranch Hand
Posts: 697
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one JSON file and task is to convert into XML. Attached is my java file through, Getting an error at line 30 Exception in thread "main" java.lang.NoSuchMethodError: nu.xom.Serializer.getEncoding()Ljava/lang/String;

Make sure you have xom.jar in your classpath?
 
vivek dhiman
Ranch Hand
Posts: 153
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

I got to know that I had the xom.jar file. & had the Serializer class in that, which doesn't have getEncoding() method. Thats the reason i am getting such error. These libraries provided by client so not able to alter . Trying to find out another solution.
 
krishna atok
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vivek,

Please try the below code snippet.

JSONObject o = new JSONObject("{'glossary': {'title': 'example glossary','GlossDiv': {'title': 'S','GlossList': {'GlossEntry': {'ID': 'SGML','SortAs': 'SGML','GlossTerm': 'Standard Generalized Markup Language','Acronym': 'SGML','Abbrev': 'ISO 8879:1986','GlossDef': {'para': 'A meta-markup language, used to create markup languages such as DocBook.', 'GlossSeeAlso': ['GML', 'XML']},'GlossSee': 'markup'}} } } }");

String xml = org.json.XML.toString(o);

System.out.println(xml);

Above stuff should work with out adding any new jars. Try and let me know with the output.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!