2013-11-28 13 views
0

비트 맵을 android에서 기본 64 문자열로 변환하고 내 dotnet 웹 서비스로 전달했습니다. android.Here에서java.lang.String 유형의 값 A는 string64를 json webservice에 전달할 때 JSONObject로 변환 될 수 없습니다.

org.json.JSONException: Value A of type java.lang.String cannot be converted to JSONObject 

오류가 인코딩도 JSONObject jobj=new JSONObject(jsonResponse);

ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
       photo.compress(Bitmap.CompressFormat.JPEG, 90, baos); 
       byte[]imagedata= baos.toByteArray(); 
       encodedImage = Base64.encodeToString(imagedata, Base64.NO_WRAP); 


JSONObject json = new JSONObject(); 
      json.put("userid", "1021"); 
      json.put("bmp", encodedImage); 

      HttpParams httpParams = new BasicHttpParams(); 
      HttpConnectionParams.setConnectionTimeout(httpParams, 
        7000); 
      HttpConnectionParams.setSoTimeout(httpParams, 7000); 
      HttpClient client = new DefaultHttpClient(httpParams); 

      HttpPost request = new HttpPost("http://192.198.0.220/WebService.asmx/Save"); 
      request.setEntity(new ByteArrayEntity(json.toString().getBytes(
        "UTF8"))); 
      request.setHeader("Content-Type","application/json"); 
      HttpResponse response = client.execute(request); 
      //HttpEntity entity = response.getEntity(); 
      String jsonResponse = EntityUtils.toString(response.getEntity()); 
      // If the response does not enclose an entity, there is no need 
      JSONObject jobj=new JSONObject(jsonResponse); 

답변

1
class AsyncCall extends AsyncTask<String, String, String> { 
    private ProgressDialog pDialog; 

    @Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 
     pDialog = new ProgressDialog(UploadBase64ImageActivity.this); 
     pDialog.setMessage("Creating Product.."); 
     pDialog.setIndeterminate(false); 
     pDialog.setCancelable(true); 
     pDialog.show(); 
        convertImage(); 
    } 

    protected String doInBackground(String... args) { 
     HttpClient httpClient = new DefaultHttpClient(); 
     HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), 
       50000); 
     HttpResponse response; 
     JSONObject json = new JSONObject(); 
     try { 
      HttpPost httpPost = new HttpPost(URLString); 

      json.put("image_str", imageJson); 
      json.put("imageName", imageName); 
      json.put("id", 1); 

      Log.e("json Object", json.toString()); 
      httpPost.setHeader("json", json.toString()); 

      StringEntity stringEntity = new StringEntity(json.toString()); 
      stringEntity.setContentEncoding(new BasicHeader(
        HTTP.CONTENT_TYPE, "application/json")); 

      httpPost.setEntity(stringEntity); 
      response = httpClient.execute(httpPost); 

      int statusCode = response.getStatusLine().getStatusCode(); 
      if (statusCode == 200) { 
       HttpEntity entity = response.getEntity(); 
       jsonResponse = EntityUtils.toString(entity); 
       Log.e("json response string in status line code", 
         jsonResponse); 

      } 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

     return null; 
    } 

    protected void onPostExecute(String file_url) { 
     pDialog.dismiss(); 
    } 
} 


private void convertImage() { 
    Bitmap bitmapImage = BitmapFactory.decodeResource(getResources(), 
      R.drawable.beautifulnames); 
     ByteArrayOutputStream baos = new ByteArrayOutputStream(); 

    Bitmap resizedImage = Bitmap.createScaledBitmap(bitmapImage, 400, 400, 
      true); 
    resizedImage.compress(Bitmap.CompressFormat.JPEG, 100, baos); 
    byte[] imageBytes = baos.toByteArray(); 
    imageJson = Base64.encodeToString(imageBytes, Base64.DEFAULT); 
} 
에 오류

A generic error occurred in GDI+. 

을 받고 를 웹 서비스에 문자열을 보낼 내 안드로이드 코드 : 나는 예외를 얻을