priyamal madushanka
priyamal madushanka

Reputation: 23

which jar libraries should i use when using json

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

Answers (3)

sushant097
sushant097

Reputation: 3746

Works as Java8:


Here is the link for JAR

For more help visit https://javaee.github.io/jsonp/

Download it and directly add in your Project.

Upvotes: 0

StaxMan
StaxMan

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 requires gson-2.4.jar (group id com.google.code.gson, artifact id gson
  • Jackson requires 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

toskv
toskv

Reputation: 31600

The missing class in the NoClassDefFoundError is located in commons-lang.jar from apache.

It can be downloaded here.

Upvotes: 3

Related Questions