我需要在sqlite中存储JSONArray,这是我如何将它解析为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中 我怎么能这样做?
答案 0 :(得分:2)
String strFields = cur.getString(cur.getColumnIndex("fields"));
mFields = fields.toJSONArray();
您可以使用以下命令从String创建JSONArray:
JSONArray mFields = new JSONArray(strFields);