0

当我记录我的名称值对时,我在控制台中得到了这个。

01-07 13:51:55.137: I/System.out(723): URL:[data={"id":"69403","timestamp":"07-01-2013 13:51:55","longitude":"-122.084095","latitude":"37.422005"}]

但我需要删除[和]。有人知道怎么做这个吗?

这是执行此操作的android代码。

json = new JSONObject(); 
        try { 

            json.put("longitude", longi); 

            json.put("latitude", lat); 
            json.put("timestamp", time); 

            json.put("id", "69403"); 


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

        /// create StringEntity with current json obejct 

        try { 
      //  StringEntity se = new StringEntity(json.toString()); 

            List <NameValuePair> nvps = new ArrayList <NameValuePair>();
            nvps.add(new BasicNameValuePair("data", json.toString()));
            httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
            System.out.println("URL:" + httpost);
            System.out.println("URL:" + nvps);


            System.out.println("send about to do post");
            try {
                response = httpclient.execute(httpost);
                System.out.println("URL:" + httpost);

            } catch (ClientProtocolException e) {
                Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            } catch (IOException e) {
                Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }
4

2 回答 2

2

在不使用 as 的情况下发布您的 jsonObject BasicNameValuePair

 StringEntity se = new StringEntity(json.toString()); 
 se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
 httppost.setEntity(se); 
于 2013-01-07T13:07:07.203 回答
0

解决代码:

在输出中使用这样的子字符串

你的输出

URL:[data={"id":"69403","timestamp":"07-01-2013 13:51:55","longitude":"-122.084095","latitude":"37.422005"}]

这样做,开始的 6 个单词将被删除或删除

String op = yourOutputString.substring(6)
于 2013-01-07T13:06:43.977 回答