【发布时间】:2020-09-08 12:37:34
【问题描述】:
我需要得到没有字符串名称的 json 数组:
代码选择Sqlite:
public Cursor getAllData() {
String selectQuery = "Select * from capturas";
SQLiteDatabase db = new MyHelper(this).getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
return cursor;
}
代码 Json:
public JSONObject createJsonObject() throws JSONException {
Cursor cursor = getAllData();
JSONObject jobj;
JSONArray arr = new JSONArray();
cursor.moveToFirst();
while (cursor.moveToNext()) {
jobj = new JSONObject();
jobj.put("sCaptID", cursor.getString(0));
jobj.put("sName", cursor.getString(1));
arr.put(jobj);
}
jobj = new JSONObject();
jobj.put("data", arr);
return jobj;
}
我需要没有“数据”的 jobj.put。
代码 JsonSend
public void postJsonToServer() throws JSONException {
JSONObject js = createJsonObject();
String url = "http://xx.1xx.xx9.xx/server";
JsonObjectRequest jsonObjReq = new JsonObjectRequest(com.android.volley.Request.Method.POST, url, js, new com.android.volley.Response.Listener<JSONObject>() {
结果 json 为:
{"data":[{
{
"id": "22",
"name": "test"
}]
}
我需要 json 结果:
[
{
"id": "22",
"name": "test"
}]
【问题讨论】: