我做了什麼至今:我創造了這個格式的JSON對象:問題從SQLite數據庫創建JSON數組值
{ "checklist": {
"id": "1", "name": "shoppping", "desc":"description", "is_editable":"false", "item": [ {"id":"3","value": "dfdf", "desc": "wwe"}, {"id":"3","value": "dfdf", "desc": "wwe"}, {"id":"3","value": "dfdf", "desc": "wwe"} ] } }
使用下面的代碼:
public static void sendjsontourl(String id) throws JSONException, IllegalStateException, IOException
{
String title;
String desc;
String creator;
Boolean is_editable;
String[] itid;
String[] itname;
String[] itdesc;
Boolean[] itchk;
Integer count;
title=DBInterface.getlistname(id);
desc=DBInterface.getlistdesc(id);
creator=DBInterface.getlistcreartor(id);
is_editable=DBInterface.geteditablemode(id);
itid=DBInterface.getitemid(id);
itname=DBInterface.getitemname(id);
itdesc=DBInterface.getitemdesc(id);
itchk=DBInterface.readdataitem(id);
count=DBInterface.getitemcount(id);
JSONObject checklist = new JSONObject();
JSONObject obj = new JSONObject();
JSONArray item = new JSONArray();
JSONObject reqObj = new JSONObject();
for(int i=0; i<count; i++)
{
reqObj.put("id",""+itid[i]);
reqObj.put("value",""+ itname[i]);
reqObj.put("desc", ""+itdesc[i]);
item.put(reqObj);
}
obj.put("item", item);
obj.put("id",""+id);
obj.put("name",""+title);
obj.put("description",""+desc);
obj.put("creator",""+creator);
obj.put("is_editable",""+is_editable);
checklist.put("checklist",obj);
Log.d("log_tag",String.valueOf(checklist));
}
我的問題:因爲你可以看到JSON對象,其中包含一個JSON數組項...該項目的值是相同的每一個項目...從sqlite數據庫中的數據獲取部分是正確的..我不能找出什麼問題以及爲什麼只存儲最後的索引值在json數組中!
請格式化你的代碼。 – m0skit0