org.json.simple.JSONObject cannot be cast to org.json.JSONObject

前端 未结 2 500
天命终不由人
天命终不由人 2020-12-11 02:24

When I run the following code...

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

  try 
  {
         


        
相关标签:
2条回答
  • 2020-12-11 02:48

    Change your code as:

      org.json.simple.JSONObject jsonObject = null;
      JSONParser parser=new JSONParser(); // this needs the "json-simple" library
    
      try 
      {
            Object obj = parser.parse(responseBody);
            jsonObject=(org.json.simple.JSONObject)obj;
      }
      catch(Exception ex)
      {
            Log.v("TEST","Exception1: " + ex.getMessage());
      }
    

    or if you are using only org.json.simple library for parsing json string then just import org.json.simple.* instead of org.json.JSONObject

    0 讨论(0)
  • 2020-12-11 03:11

    You have imported the wrong class. Change

    import org.json.JSONObject;
    

    to

    import org.json.simple.JSONObject;
    
    0 讨论(0)
提交回复
热议问题