简体   繁体   中英

A problem when creating an instance of JSONObject

I am new to java, and I have seen a lot of people using JSONObject like this:

 String content ="....";
 JSONObject Object1 = new JSONObject(content);

But when I do that, there appears that: enter image description here

What's wrong, please help me.(I have "import net.sf.json.JSONObject")

The JSONObject you provided is from the popular org.json library which contains a constructor like your example.

So simply switch to this lib.

What it seems, is that you are importing the wrong library. The library that you are using doesn't have a constructor that receives a string parameter only a boolean:

http://json-lib.sourceforge.net/apidocs/jdk15/net/sf/json/JSONObject.html#JSONObject(boolean)

The library that you are trying to use when you are initializing a new instance of JSONObject is from Google:

https://developer.android.com/reference/org/json/JSONObject#JSONObject(java.lang.String)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM