我试图将字符串转换为使用下面的代码JSONObject
对象,但我得到字符串到JSON的转换问题
Exception in thread "main" java.lang.ClassCastException:
org.json.simple.JSONObject cannot be cast to net.sf.json.JSONObject .
来源:
import net.sf.json.JSONObject;
import org.json.simple.parser.JSONParser;
public static void run(JSONObject jsonObject) {
System.out.println("in run--");
}
public static void main(String[] args) throws Exception {
System.out.println("here");
String json = "{\"task\": \"com.ge.dbt.workers.surveytoexcel.worker.SurveyWorker\",\"prod_id\": 12345,\"survey_id\": 5666,\"person_id\": 18576567,\"req_date\": \"12\12\2012\"}";
JSONObject jsonObj;
JSONParser parser = new JSONParser();
Object obj = parser.parse(json);
jsonObj = (JSONObject) obj;
run(jsonObj);
}
这里有什么问题?
-1:'网.sf.json.JSONObject'不h一个'String'构造函数。 http://json-lib.sourceforge.net/apidocs/jdk15/net/sf/json/JSONObject.html –
我真的很抱歉!我把它收回。哦,我的坏!我只是把'org.codehaus.jettison.json.JSONObject'和'net.sf.json.JSONObject'混淆了。无论如何感谢您指出了这一点。 @大卫格兰特是正确的,我错了。伙计们对于错误的信息感到抱歉。 – Nokia808Freak
我刚纠正它。我希望这有帮助 – Nokia808Freak