人々: "とjava.lang.ClassCastException:net.sf.json.JSONObject と互換性がjava.lang.Stringで
JSONにClassCastException
61: for(Object myObject : studentsGradeArray)
62: {
63:
64: JSONObject studentGradeJSON = (JSONObject) myObject;
これにはどのような原因が考えられますか?
人々: "とjava.lang.ClassCastException:net.sf.json.JSONObject と互換性がjava.lang.Stringで
JSONにClassCastException
61: for(Object myObject : studentsGradeArray)
62: {
63:
64: JSONObject studentGradeJSON = (JSONObject) myObject;
これにはどのような原因が考えられますか?
言いたいことがあります。 studentsGradeArray
内のすべてのオブジェクトをJSONオブジェクトことになっていると仮定すると...
for(Object myObject : studentsGradeArray) {
JSONObject studentGradeJSON = JSONObject.fromObject(myObject);
// the rest of your code
}
詳しい情報はJSONObject documentation
studentsGradeArrayの要素は、JSONObject型ではなくString型です。
あなたは、あなたが必要とJSONObject
の代わりにString
オブジェクトを取得しているかのように見えます
JSONObject studentGradeJSON = new JSONObject(myObject)
didntの仕事で見つけることができます:未定義である – t0mcat
おかげNT3RPが..コンストラクタJSONObject(オブジェクト)がより信頼できるもの。あなたの解決策やアマデウスは?あなたもStringからキャストを追加したからです。 – t0mcat
Didnt work:コンストラクタJSONObject(String)が定義されていません – t0mcat
申し訳ありません、あなたは[このライブラリ](http://www.json.org/javadoc/org/json/JSONObject.html)を使用していたと仮定していました。私は私の答えを訂正します。 – NT3RP