-3

我需要将 JSONArray 存储在 sqlite 中,这是我将其解析为 String 以存储在 SQLite 中的方式

DataBase dba = new DataBase(getActivity(), "moduleDesc");
                    JSONObject mModule = CommonUtility.getDescribeObject(
                            mSP, "describe", mModuleName);
                    boolean deleteable = mModule.getBoolean("deleteable");
                    int flag = (deleteable) ? 1 : 0;
                    boolean createable = mModule.getBoolean("createable");
                    int flag1 = (createable) ? 1 : 0;
                    boolean updateable = mModule.getBoolean("updateable");
                    int flag2 = (updateable) ? 1 : 0;
                    String name = mModule.getString("name");
                    String label = mModule.getString("label");
                    String labelFields = mModule.getString("labelFields");
                    JSONArray mFields = mModule.getJSONArray("fields");
                    String fields = mFields.toString();
                    boolean exists = dba.Exists(name);
                    if (exists == false) {
                        dba.insertintomoduleDesc(flag, flag1, flag2, name,
                                labelFields, label,fields);
                    }
                    dba.close();

现在我把它转换回来

DataBase dba = new DataBase(con);
    cur = dba.getmod(moduleName);
     mIsCreatable = cur.getInt(cur.getColumnIndex("createable"));
     mIsUpdateable = cur.getInt(cur.getColumnIndex("updateable"));
     mIsDeletable = cur.getInt(cur.getColumnIndex("deleteable"));
     mName = cur.getString(cur.getColumnIndex("name"));
     mLabel = cur.getString(cur.getColumnIndex("label"));
     mLabelFields = cur.getString(cur.getColumnIndex("labelfields"));
     String fields = cur.getString(cur.getColumnIndex("fields"));
     mFields = fields.toJSONArray();

它说 toJSONArray() 未定义字符串,但我的 Jsonarray 正在解析并存储在 sqlite 中,我该怎么做?

4

1 回答 1

2
 String strFields = cur.getString(cur.getColumnIndex("fields"));
 mFields = fields.toJSONArray();

而不是上面,您可以使用以下方法从 String 创建 JSONArray:

JSONArray mFields = new JSONArray(strFields);
于 2012-07-30T11:54:52.997 回答