1

I am getting this compilation error:

cannot find symbol Constructor JSONObject(java.lang.String)

Can any one explain what is wrong with it?

String jsnString = new String("{\"fname\":\"DKP\",\"lname\":\"patel\"}");
JSONObject jObj = new JSONObject(new String(jsnString)); 

I also tried with:

JSONObject jObj = new JSONObject(jsnString); 
11
  • also I replaced JSONObject jObj = new JSONObject(new String(jsnString)); with JSONObject jObj = new JSONObject(jsnString); Commented Aug 2, 2012 at 14:13
  • What JSON library are you using? (ps: the second version is better, there is no need to create a new string like you do in the first one) Commented Aug 2, 2012 at 14:17
  • I am using json-lib-2.2.2-jdk15.jar Commented Aug 2, 2012 at 14:18
  • I just checked the javadoc and there is no JSONObject constructor that takes a String. There only is a no-argument constructor and another one that takes a boolean. Are you sure you are not mixing 2 different JSON libraries? Commented Aug 2, 2012 at 14:22
  • json.org/javadoc/org/json/JSONObject.html Commented Aug 2, 2012 at 14:24

1 Answer 1

1

You should check to see if it is correctly linked and imported. Can you use any of the other classes / static methods in the class?

Sign up to request clarification or add additional context in comments.

1 Comment

yes, becoz when I use JSONObject jObj = new JSONObject("{\"fname\":\"DKP\",\"lname\":\"patel\"}"); , it is compiling without error..

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.