0

I was supposed to convert to JSON string to XML. As suggested in one StackOverflow answer, I used the XML.toString method.

        String json_data = "{\"student\":{\"name\":\"Neeraj Mishra\", \"age\":\"22\"}}";
    JSONObject obj = new JSONObject(json_data);

    //converting json to xml
    String xml_data = XML.toString(obj);

    System.out.println(xml_data);

The above method is working perfectly fine for the latest version of org.json but my project uses 20080701 version of org.json and it is throwing the following error at this method XML.toString(obj);

Exception in thread "main" java.lang.NoSuchMethodError: 
org.json.JSONObject.entrySet()Ljava/util/Set;
at org.json.XML.toString(XML.java:502)
at org.json.XML.toString(XML.java:471)
at com.testing.main(testing.java:13) 

And I cannot update the version.

4
  • 1
    But you are not using entrySet in your code, please post full stack trace so we can see what causes the exception. Commented Apr 15, 2019 at 7:36
  • Exception in thread "main" java.lang.NoSuchMethodError: org.json.JSONObject.entrySet()Ljava/util/Set; at org.json.XML.toString(XML.java:502) at org.json.XML.toString(XML.java:471) at com.yodlee.aim.autoconfig.services.testing.main(testing.java:500) This is the stacktrace Commented Apr 15, 2019 at 7:37
  • Add that to the question instead by editing it and also point out what row this is in your code since we don't know the line numbers Commented Apr 15, 2019 at 7:39
  • updated @JoakimDanielson Commented Apr 15, 2019 at 7:52

1 Answer 1

1

You can user the older version of org.json like "20160212"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.