org.json.simple.JSONObject无法强制转换为org.json.JSONObject

Mic*_*ick 6 android json

当我运行以下代码时......

  JSONObject jsonObject = null;
  JSONParser parser=new JSONParser(); // this needs the "json-simple" library

  try 
  {
        Object obj = parser.parse(responseBody);
        jsonObject=(JSONObject)obj;
  }
  catch(Exception ex)
  {
        Log.v("TEST","Exception1: " + ex.getMessage());
  }
Run Code Online (Sandbox Code Playgroud)

...在运行时我在日志输出中看到以下内容:

Exception1: org.json.simple.JSONObject cannot be cast to org.json.JSONObject
Run Code Online (Sandbox Code Playgroud)

我不明白为什么.

Hen*_*nry 17

您导入了错误的类.更改

import org.json.JSONObject;
Run Code Online (Sandbox Code Playgroud)

import org.json.simple.JSONObject;
Run Code Online (Sandbox Code Playgroud)