【发布时间】:2015-01-24 21:10:35
【问题描述】:
我正在开发一个 android 应用程序,该应用程序必须将一个 json 格式的 java 对象保存到 SQLite 数据库中。我为这个操作编写了代码,然后他们必须提取 Json 对象并将其重新转换为 Java 对象。
当我尝试调用将json对象反序列化为字符串的方法时,我在Android Studio中发现了这个错误:unhandled exception org.json.jsonexception
当我尝试捕获 JSONException e 时,程序运行但不反序列化 json 对象。
这是方法的代码:
private void read() throws JSONException {
SQLiteDatabase db = mMioDbHelper.getWritableDatabase();
String[] columns = {"StringaAll"};
Cursor c = db.query("Alle", columns, null, null, null, null,null );
while(c.moveToNext()) {
String stringaRis = c.getString(0);
JSONObject jObj = new JSONObject(stringaRis);
String sPassoMed = jObj.getString("passoMed");
final TextView tView = (TextView) this.findViewById(R.id.mainProvaQuery);
tView.setText(sPassoMed);
// }
}
}
你能帮帮我吗?
【问题讨论】:
-
你能发布 JSONException 的堆栈跟踪吗?
-
你是这个意思吗? 577 java.lang.NumberFormatException 28 1 java.lang.Long.invalidLong(Long.java:124) 568 java.lang.NumberFormatException 28 1 java.lang.StringToReal.invalidReal(StringToReal.java:63) 555 org.json.JSONException 28 1 org.json.JSON.typeMismatch(JSON.java:111)