When I run the following code...
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());
}
...at runtime I see the following in my log output:
Exception1: org.json.simple.JSONObject cannot be cast to org.json.JSONObject
I don't understand why.
You have imported the wrong class. Change
import org.json.JSONObject;
to
import org.json.simple.JSONObject;
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With