开发者

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) 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜