如何从sqlite获取所有图像base64字符串?

时间:2016-09-01 10:37:09

标签: android sqlite cursor

我的sqlite数据库中有base64字符串,我将所有这些记录发送到服务器。我遇到的问题是,当我尝试将这些base64字符串发送到服务器时,它只发送第一个原始记录,然后它为其他行发送null。我调试我的代码,我看到它第一次它chek我的if条件,但第二行它chek其他条件。我该如何解决?

class async_SaveImage extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... params) {

            SoapObject request = new SoapObject(namespacegetlistdata, method_name__image);

            cursorImage = db.rawQuery("select * from FieldTestDataFinal Where isSend ='N'", null);
            /*for(int i=0; i<cursor.getCount(); i++)
            {*/
            int k = 0;
            try {
                if (cursorImage.moveToFirst()) {

/*while (cursor.moveToNext())*/
                    do {
                        JSONArray arr = new JSONArray();
                        JSONObject jsonObject = new JSONObject();

                        //request.properties.clear();
                        if (k == 0) {
                            request.addProperty("fileByte1", cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE1")));//add the parameters
                            request.addProperty("fileName1", cursorImage.getString(cursorImage.getColumnIndex("fileName1")));//add the parameters

                            request.addProperty("fileByte2", cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE2")));//add the parameters
                            request.addProperty("fileName2", cursorImage.getString(cursorImage.getColumnIndex("fileName2")));//add the parameters

                            request.addProperty("fileByte3", cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE3")));//add the parameters
                            request.addProperty("fileName3", cursorImage.getString(cursorImage.getColumnIndex("fileName3")));//add the parameters

                            request.addProperty("fileByte4", cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE4")));//add the parameters
                            request.addProperty("fileName4", cursorImage.getString(cursorImage.getColumnIndex("fileName4")));//add the parameters

                            request.addProperty("fileByte5", cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE5")));//add the parameters
                            request.addProperty("fileName5", cursorImage.getString(cursorImage.getColumnIndex("fileName5")));//add the parameters

                            request.addProperty("fileByte6", cursorImage.getString(cursorImage.getColumnIndex("SIGNATURE_CONSUMER")));//add the parameters
                            request.addProperty("fileName6", cursorImage.getString(cursorImage.getColumnIndex("fileName6")));//add the parameters
                            // request.addProperty("fileName", "123.jpeg");//add the parametershe parameters
                        } else {
                            request.setProperty(0, cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE1")));//add the parameters
                            request.setProperty(1, cursorImage.getString(cursorImage.getColumnIndex("fileName1")));//add the parameters

                            request.setProperty(0, cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE2")));//add the parameters
                            request.setProperty(1, cursorImage.getString(cursorImage.getColumnIndex("fileName2")));//add the parameters

                            request.setProperty(0, cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE3")));//add the parameters
                            request.setProperty(1, cursorImage.getString(cursorImage.getColumnIndex("fileName3")));//add the parameters

                            request.setProperty(0, cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE4")));//add the parameters
                            request.setProperty(1, cursorImage.getString(cursorImage.getColumnIndex("fileName4")));//add the parameters

                            request.setProperty(0, cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE5")));//add the parameters
                            request.setProperty(1, cursorImage.getString(cursorImage.getColumnIndex("fileName5")));//add the parameters

                            request.setProperty(0, cursorImage.getString(cursorImage.getColumnIndex("SIGNATURE_CONSUMER")));//add the parameters
                            request.setProperty(1, cursorImage.getString(cursorImage.getColumnIndex("fileName6")));//add the parameters
                        }
                        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);//set soap version
                        envelope.setOutputSoapObject(request);
                        envelope.dotNet = true;
                        try {
                            HttpTransportSE androidHttpTransport = new HttpTransportSE(url_getlistdata);
                            androidHttpTransport.call(soap_action_uploadImage, envelope);  // this is the actual part that will call the webservice
                            //SoapPrimitive prim = (SoapPrimitive) envelope.getResponse();  // Get the SoapResult from the envelope body.
                            SoapObject response = (SoapObject) envelope.bodyIn;

                            //hideDialog();


                        } catch (Exception e) {
                            e.printStackTrace();
                            Log.d("myError -", String.valueOf(e));
                        }
                        k++;
                    } while (cursorImage.moveToNext());

                       /* object = new JSONObject();
                        object.put("data", arr);*/
                }
                cursorImage.close();


            } catch (Exception e) {

            }
            // }

            return resultSaveAllData;

        }

        @Override
        protected void onPostExecute(String result1) {
            try {

            } catch (Exception e) {

            }
            super.onPostExecute(result1);

        }
    }

1 个答案:

答案 0 :(得分:0)

试试这个,

var items = [
{
    "id": 1,
    "name": "Furniture & Fixture",
    "choices": [
    {
      "id": 1,
      "req_goods": "table",
      "qty": "10"
    },
    {
      "id": 2,
      "req_goods": "chair",
      "qty": "5"
    }]
}, {
    "id": 2,
    "name": "Miscellaneous Property",
    "choices": [
    {
      "id": 1,
      "req_goods": "Office Rent",
      "qty": "1"
    }]
}];

function removeChoice(parentId, choiceId) {
  for (var i = 0; i < items.length; i++) {
    if (items[i].id === parentId) {
      for (var j = 0; j < items[i].choices.length; j++) {
      	if (items[i].choices[j].id === choiceId) {
          items[i].choices.splice(j, 1);
          break;
        }
      }
      
      break;
    }
  }
}

removeChoice(1, 1);
console.log(items);