15

First: can someone provide an explanation of the differences between org.json.simple.JSONObject and org.json.JSONObject?

Second: I have a code with org.json.JSONObject and org.json.JSONException. When I edit the code in eclipse ( JUNO) it resolves the type of JSONException and imports the package org.json.JSONException but when I run the project using maven in command line I have a problem ( JSONException cannot be resolved to a type). I tried to solve the issue by adding dependency to pom.xml like this :

<dependency>
    <groupId>com.googlecode.json-simple</groupId>
    <artifactId>json-simple</artifactId>
    <version>1.1</version>
 </dependency>

but I am not sure if it is the right one . I even download the jar of org. java-json.jar and add it to web deployment assembly but still the same error. Can anyone help ?

David Brossard
  • 13,584
  • 6
  • 55
  • 88
Cooper
  • 208
  • 2
  • 3
  • 10

1 Answers1

18

org.json and org.json.simple are two different Java libraries, which are incompatible with each other. The fact that they have the same name is only a misleading coincidence.

To compare the two libraries:

General comparison = http://www.rojotek.com/blog/2009/05/07/a-review-of-5-java-json-libraries/ org.json.simple = http://code.google.com/p/json-simple/
org.json = http://json.org/java

MikeFHay
  • 8,562
  • 4
  • 31
  • 52
James Game
  • 547
  • 4
  • 8
  • 1
    Both http://json.org/java and http://www.rojotek.com/blog/2009/05/07/a-review-of-5-java-json-libraries/ is not found. – hemanto Dec 20 '17 at 06:55
  • 1
    The two libraries are purposeful, so that people doing google searches for `org.json` parsing, would also land on `org.json.simple` code, since simple is an adjective. So during coding tests, you find that copying in code designed to read, iterate, add/get, rewrite, then finally transmit JSON in Java would be impossibly mired in incompatibility between any two pieces of code. Every joint is incompatible with every other. – Eric Leschinski Sep 12 '18 at 20:43
  • Like a mechanic given given a tool set not only of standard and metric, but also of korean, egyptian, klingon, and ponytype. No tool is compatible with any other, his progress halted like a child with a legoset where no two lego fit with any other. Keep up the subterfuge boys, you're doing Great! I'd say keep up the good work, but preventing you is the reason for this. So keep up the not-working. – Eric Leschinski Sep 12 '18 at 20:44