删除BasicNameValuePair周围的括号

时间:2013-01-07 12:58:02

标签: android json

当我记录我的namevaluepair时,我会在我的控制台中找到它。

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();
            }

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:0)

解决代码:

将这样的子字符串用于输出

你的输出

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

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

String op = yourOutputString.substring(6)
相关问题