0

i want to send json data to my page , here is the code :

response.setContentType("application/json");
    String jsonObject = "{ key1 = value1, key2 = value2 }";
    JSON json = JSONSerializer.toJSON(jsonObject);
    PrintWriter out = response.getWriter();
    out.print(json);
    out.flush();
    return null;

i get this error :

java.lang.NoClassDefFoundError: net/sf/json/JSONSerializer

i'm using jdk1.7 and json : -json-lib-2.4-jdk15.jar -json-lib-2.4-jdk15-javadoc.jar -json-lib-2.4-jdk15-sources.jar

ezmorph : -ezmorph-1.0.6.jar

and commons-lang.jar

why i'm getting this error ?

3
  • Where did you install the json-lib-2.4-jdk15.jar? Commented Oct 30, 2012 at 11:52
  • 1
    You should check whether the json-lib jar file is actually present in the classpath when you run the servlet, e.g. in WEB-INF/lib/. Commented Oct 30, 2012 at 11:53
  • @Azodious i installed them into WEB-INF/lib/ Commented Oct 30, 2012 at 11:57

1 Answer 1

2

Try:

String myjsonObject = "{ key1 = value1, key2 = value2 }";
JSONObject json = (JSONObject) JSONSerializer.toJSON( myjsonObject );
Sign up to request clarification or add additional context in comments.

3 Comments

May be you should check How to add all your classpaths in eclipse: check this link
i added the jars in both methos external and internal , same issue
the problem was due to that i should redeploy the project in the server

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.