JSON ClassCastException
Folks I am trying to populate a bean from a JSONOject but its throwing me the exception online 64: "java.lang.ClassCastException: java.lang.String incompatible with net.s开发者_开发技巧f.json.JSONObject "
61: for( Object myObject : studentsGradeArray )
62: {
63:
64: JSONObject studentGradeJSON = (JSONObject) myObject;
What could be the possible reason for this?
It looks as though you are getting a String
object instead of the JSONObject
that you require. Assuming that all objects in studentsGradeArray
are supposed to be JSON Objects...
for( Object myObject : studentsGradeArray ) {
JSONObject studentGradeJSON = JSONObject.fromObject(myObject);
// the rest of your code
}
More information can be found in the JSONObject documentation
The elements of studentsGradeArray are of type String, not of type JSONObject.
You may want to say
JSONObject studentGradeJSON = new JSONObject(myObject)
精彩评论