Reputation: 23
im very new to json and i'm trying to run json with java. i found 2 json jar files from internet called
1)java-json.jar
2)json-lib-2.4-jdk15.jar
if im gonna run a java code with using json do i need to include these 2 jar libraries or a single one is enough. i included both libs and tried to run a code and i see this exception coming
NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
i realize this is beacause of a missing lib or something bt i dont know the jar files i should include when running a java code if its using json can some one tell me every jar file i should use and my code is given below
public static void main(String[] args) {
json = new JSONObject();
map = new HashMap<String, String>();
map.put("name", "priyamal");
map.put("age", "21");
json.accumulateAll(obj.map);
printJsonStrin(json.toString());
}
public static void printJsonStrin(String jsonstr){
System.out.println(jsonstr);
}
Upvotes: 1
Views: 12747
Reputation: 3746
Works as Java8:
For more help visit https://javaee.github.io/jsonp/
Download it and directly add in your Project.
Upvotes: 0
Reputation: 116522
The two most popular and fully-featured Java JSON libraries according to Maven Repository are:
and jars for both are accessible via Maven:
gson-2.4.jar
(group id com.google.code.gson
, artifact id gson
jackson-databind-2.6.2.jar
(group id com.fasterxml.jackson.core
, artifact jackson-databind
), as well as 2 supporting jars (jackson-core
for streaming parser, jackson-annotations
for annotation suport)Jars that you listed are for other lesser commonly used packages (one for json-lib
, http://json-lib.sourceforge.net/ is pretty old; other I don't even know what it is), so I would not recommend you use them.
Upvotes: 5