Error in converting List to JSON in Java (3), javajson

Source: Internet
Author: User

Error in converting List to JSON in Java (3), javajson

1. Error description

Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpherat net.sf.json.util.CycleDetectionStrategy.<clinit>(CycleDetectionStrategy.java:37)at net.sf.json.JsonConfig.<clinit>(JsonConfig.java:65)at net.sf.json.JSONArray.fromObject(JSONArray.java:105)at com.you.model.ListToJSON.main(ListToJSON.java:29)Caused by: java.lang.ClassNotFoundException: net.sf.ezmorph.Morpherat java.net.URLClassLoader$1.run(URLClassLoader.java:366)at java.net.URLClassLoader$1.run(URLClassLoader.java:355)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:354)at java.lang.ClassLoader.loadClass(ClassLoader.java:425)at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)at java.lang.ClassLoader.loadClass(ClassLoader.java:358)... 4 more

2. Error cause

From the phrase "Caused by: java. lang. ClassNotFoundException: net. sf. ezmorph. Morpher", we can see that jar is missing.


3. Solution

Copy the ezmorph-1.0.6.jar to the lib directory


How to convert list into json in java

// Need to use json-lib.jar, you can download here: json-lib.sourceforge.net/
// Code instance
List <String> list = new ArrayList <String> ();
List. add ("abc ");
List. add ("123 ");

Net. sf. json. JSONArray jsonArray = net. sf. json. JSONArray. fromObject (list );
System. out. println (jsonArray. toString ());

Conversion from List set to json in java

Exception has told you, obviously the package is missing, should be missing the commons-beanutils.jar File

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.