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

前端 未结 2 507
天命终不由人
天命终不由人 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

提交回复
热议问题