不幸的是查询已停止

时间:2013-10-09 07:33:48

标签: android

这里我正在收集用户数据现在我想发送下面提到的数据这个数据..  但是,当我运行应用程序..显示一个对话框,并写为不幸的查询  已停止。请任何人知道如何发送数据任何URL请建议我。

try
    {
        JSONObject action=new JSONObject();

        JSONObject user=new JSONObject();
        action.put("person_name", Person_Name);
        action.put("mobile_number", Mobile_Number);
        action.put("person_query", Person_Query);
        action.put("action", Action);
        user.put("result",action);
       jsonString1 =user.toString();
   }
    catch (Exception je)
    {

    }
     Toast.makeTex(DetailsActivity.this,jsonString1,Toast.LENGTH_LONG).show();


   // Sending JSON Over the Network
     String wurl="http://www.androidbegin.com/tutorial/jsonpar.txt";

    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost httppostreq = new HttpPost(wurl);
    StringEntity se = null;
   try {

    se = new StringEntity( jsonString1);

       } catch (UnsupportedEncodingException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
       } 
       se.setContentType("application/json;charset=UTF-8");
       se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,      "application/json;charset=UTF-8"));
        httppostreq.setEntity(se);
    try {

     HttpResponse httpresponse = httpclient.execute(httppostreq);

         } catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
        } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

1 个答案:

答案 0 :(得分:1)

try catch

中尝试此操作
HttpPost request = new HttpPost(Your URL);
                    JSONObject returnedJObject;
                    returnedJObject = new JSONObject(JSONdata.toString());
                    JSONStringer json = new JSONStringer();
                    StringBuilder sb=new StringBuilder();


                    if (returnedJObject!=null)
                    {
                        Iterator<String> itKeys = returnedJObject.keys();
                        if(itKeys.hasNext())
                            json.object();
                        while (itKeys.hasNext())
                        {
                            String k=itKeys.next();
                            json.key(k).value(returnedJObject.get(k));
                            //Log.e("keys "+k,"value "+returnedJObject.get(k).toString());
                        }             
                    }
                   json.endObject();


                   StringEntity entity;

                   entity = new StringEntity(json.toString());

                   entity.setContentType("application/json;charset=UTF-8");
                  // entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json;charset=UTF-8"));
                   request.setHeader("Accept", "application/json");
                   request.setEntity(entity);

                   HttpResponse response =null;
                   DefaultHttpClient httpClient = new DefaultHttpClient();

                   HttpConnectionParams.setSoTimeout(httpClient.getParams(), 30000);
                   HttpConnectionParams.setConnectionTimeout(httpClient.getParams(),50000);

                   response = httpClient.execute(request);

                   InputStream in;
                   in = response.getEntity().getContent();

                   BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                   String line = null;
                   while((line = reader.readLine()) != null){
                       sb.append(line);
                   }


                   return new JSONObject(sb.toString());